Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b3874a

Browse files
all calculations have explicit integer conversions
1 parent c763884 commit 8b3874a

File tree

1 file changed

+12
-63
lines changed

1 file changed

+12
-63
lines changed

‎lib/ImageResize.php‎

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,7 @@ public function imageCreateJpegfromExif($filename)
203203
}
204204

205205
if ($orientation === 5 || $orientation === 4 || $orientation === 7) {
206-
if(function_exists('imageflip')) {
207-
imageflip($img, IMG_FLIP_HORIZONTAL);
208-
} else {
209-
$this->imageFlip($img, IMG_FLIP_HORIZONTAL);
210-
}
206+
imageflip($img, IMG_FLIP_HORIZONTAL);
211207
}
212208

213209
return $img;
@@ -455,12 +451,12 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
455451
{
456452
if ($this->getSourceHeight() > $this->getSourceWidth()) {
457453
$ratio = $max_long / $this->getSourceHeight();
458-
$short = $this->getSourceWidth() * $ratio;
454+
$short = (int) ($this->getSourceWidth() * $ratio);
459455

460456
$this->resize($short, $max_long, $allow_enlarge);
461457
} else {
462458
$ratio = $max_long / $this->getSourceWidth();
463-
$short = $this->getSourceHeight() * $ratio;
459+
$short = (int) ($this->getSourceHeight() * $ratio);
464460

465461
$this->resize($max_long, $short, $allow_enlarge);
466462
}
@@ -478,7 +474,7 @@ public function resizeToLongSide($max_long, $allow_enlarge = false)
478474
public function resizeToHeight($height, $allow_enlarge = false)
479475
{
480476
$ratio = $height / $this->getSourceHeight();
481-
$width = $this->getSourceWidth() * $ratio;
477+
$width = (int) ($this->getSourceWidth() * $ratio);
482478

483479
$this->resize($width, $height, $allow_enlarge);
484480

@@ -495,7 +491,7 @@ public function resizeToHeight($height, $allow_enlarge = false)
495491
public function resizeToWidth($width, $allow_enlarge = false)
496492
{
497493
$ratio = $width / $this->getSourceWidth();
498-
$height = $this->getSourceHeight() * $ratio;
494+
$height = (int) ($this->getSourceHeight() * $ratio);
499495

500496
$this->resize($width, $height, $allow_enlarge);
501497

@@ -518,11 +514,11 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
518514

519515
$ratio = $this->getSourceHeight() / $this->getSourceWidth();
520516
$width = $max_width;
521-
$height = $width * $ratio;
517+
$height = (int) ($width * $ratio);
522518

523519
if ($height > $max_height) {
524520
$height = $max_height;
525-
$width = (int) round($height / $ratio);
521+
$width = (int) ($height / $ratio);
526522
}
527523

528524
return $this->resize($width, $height, $allow_enlarge);
@@ -536,8 +532,8 @@ public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
536532
*/
537533
public function scale($scale)
538534
{
539-
$width = $this->getSourceWidth() * $scale / 100;
540-
$height = $this->getSourceHeight() * $scale / 100;
535+
$width = (int) ($this->getSourceWidth() * $scale / 100);
536+
$height = (int) ($this->getSourceHeight() * $scale / 100);
541537

542538
$this->resize($width, $height, true);
543539

@@ -608,7 +604,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
608604
if ($ratio_dest < $ratio_source) {
609605
$this->resizeToHeight($height, $allow_enlarge);
610606

611-
$excess_width = ($this->getDestWidth() - $width) / $this->getDestWidth() * $this->getSourceWidth();
607+
$excess_width = (int) (($this->getDestWidth() - $width) * $this->getSourceWidth() / $this->getDestWidth());
612608

613609
$this->source_w = $this->getSourceWidth() - $excess_width;
614610
$this->source_x = $this->getCropPosition($excess_width, $position);
@@ -617,7 +613,7 @@ public function crop($width, $height, $allow_enlarge = false, $position = self::
617613
} else {
618614
$this->resizeToWidth($width, $allow_enlarge);
619615

620-
$excess_height = ($this->getDestHeight() - $height) / $this->getDestHeight() * $this->getSourceHeight();
616+
$excess_height = (int) (($this->getDestHeight() - $height) * $this->getSourceHeight() / $this->getDestHeight());
621617

622618
$this->source_h = $this->getSourceHeight() - $excess_height;
623619
$this->source_y = $this->getCropPosition($excess_height, $position);
@@ -727,60 +723,13 @@ protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
727723
return $size;
728724
}
729725

730-
/**
731-
* Flips an image using a given mode if PHP version is lower than 5.5
732-
*
733-
* @param resource $image
734-
* @param integer $mode
735-
* @return null
736-
*/
737-
public function imageFlip($image, $mode)
738-
{
739-
switch($mode) {
740-
case self::IMG_FLIP_HORIZONTAL: {
741-
$max_x = imagesx($image) - 1;
742-
$half_x = $max_x / 2;
743-
$sy = imagesy($image);
744-
$temp_image = imageistruecolor($image)? imagecreatetruecolor(1, $sy): imagecreate(1, $sy);
745-
for ($x = 0; $x < $half_x; ++$x) {
746-
imagecopy($temp_image, $image, 0, 0, $x, 0, 1, $sy);
747-
imagecopy($image, $image, $x, 0, $max_x - $x, 0, 1, $sy);
748-
imagecopy($image, $temp_image, $max_x - $x, 0, 0, 0, 1, $sy);
749-
}
750-
break;
751-
}
752-
case self::IMG_FLIP_VERTICAL: {
753-
$sx = imagesx($image);
754-
$max_y = imagesy($image) - 1;
755-
$half_y = $max_y / 2;
756-
$temp_image = imageistruecolor($image)? imagecreatetruecolor($sx, 1): imagecreate($sx, 1);
757-
for ($y = 0; $y < $half_y; ++$y) {
758-
imagecopy($temp_image, $image, 0, 0, 0, $y, $sx, 1);
759-
imagecopy($image, $image, 0, $y, 0, $max_y - $y, $sx, 1);
760-
imagecopy($image, $temp_image, 0, $max_y - $y, 0, 0, $sx, 1);
761-
}
762-
break;
763-
}
764-
case self::IMG_FLIP_BOTH: {
765-
$sx = imagesx($image);
766-
$sy = imagesy($image);
767-
$temp_image = imagerotate($image, 180, 0);
768-
imagecopy($image, $temp_image, 0, 0, 0, 0, $sx, $sy);
769-
break;
770-
}
771-
default:
772-
return null;
773-
}
774-
imagedestroy($temp_image);
775-
}
776-
777726
/**
778727
* Enable or not the gamma color correction on the image, enabled by default
779728
*
780729
* @param bool $enable
781730
* @return static
782731
*/
783-
public function gamma($enable = true)
732+
public function gamma($enable = false)
784733
{
785734
$this->gamma_correct = $enable;
786735

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /