Skip to content

Commit 2cf6b6c

Browse files
towelrolandstarke
authored andcommitted
Fix warnings "Implicit conversion from float to int loses precision" and "Creation of dynamic property is deprecated"
1 parent 71588c7 commit 2cf6b6c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Smartcrop.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ class Smartcrop
6565
'outsideImportance' => -0.5,
6666
'boostWeight' => 100.0,
6767
'ruleOfThirds' => true,
68-
'prescale' => true,
68+
'preScale' => true,
6969
'imageOperations' => null,
7070
'canvasFactory' => 'defaultCanvasFactory',
7171
'debug' => false
7272
];
7373
public $options = [];
7474
public $scale;
75-
public $prescale;
75+
public $preScale;
7676
public $image;
7777
public $od = [];
7878
public $sample = [];
@@ -88,7 +88,7 @@ public function __construct(Image $image, array $options = [])
8888
}
8989

9090
$this->scale = 1;
91-
$this->prescale = 1;
91+
$this->preScale = 1;
9292
$this->image = $image;
9393
$this->canvasImageScale();
9494
}
@@ -107,7 +107,7 @@ protected function canvasImageScale()
107107

108108
$this->options['minScale'] = min($this->options['maxScale'], max(1 / $scale, $this->options['minScale']));
109109

110-
if ($this->options['prescale'] !== false) {
110+
if ($this->options['preScale'] !== false) {
111111
$this->preScale = 1 / $scale / $this->options['minScale'];
112112
if ($this->preScale < 1) {
113113
$this->image->resize(ceil($imageOriginalWidth * $this->preScale), ceil($imageOriginalHeight * $this->preScale));
@@ -371,7 +371,9 @@ protected function importance($crop, $x, $y)
371371
*/
372372
protected function thirds($x)
373373
{
374-
$x = (($x - (1 / 3) + 1.0) % 2.0 * 0.5 - 0.5) * 16;
374+
// Use fmod for floating-point modulus to avoid implicit float->int conversion
375+
$x = fmod(($x - (1 / 3) + 1.0), 2.0);
376+
$x = ($x * 0.5 - 0.5) * 16;
375377
return max(1.0 - $x * $x, 0.0);
376378
}
377379
/**

0 commit comments

Comments
 (0)