Skip to content

Commit b3d3842

Browse files
imageflip function added for PHP < 5.5
1 parent 22a489f commit b3d3842

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lib/ImageResize.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,50 @@ protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
523523
return $size;
524524
}
525525
}
526+
527+
// imageflip definition for PHP < 5.5
528+
if (!function_exists('imageflip')) {
529+
define('IMG_FLIP_HORIZONTAL', 0);
530+
define('IMG_FLIP_VERTICAL', 1);
531+
define('IMG_FLIP_BOTH', 2);
532+
533+
function imageflip($image, $mode) {
534+
switch ($mode) {
535+
case IMG_FLIP_HORIZONTAL: {
536+
$max_x = imagesx($image) - 1;
537+
$half_x = $max_x / 2;
538+
$sy = imagesy($image);
539+
$temp_image = imageistruecolor($image)? imagecreatetruecolor(1, $sy): imagecreate(1, $sy);
540+
for ($x = 0; $x < $half_x; ++$x) {
541+
imagecopy($temp_image, $image, 0, 0, $x, 0, 1, $sy);
542+
imagecopy($image, $image, $x, 0, $max_x - $x, 0, 1, $sy);
543+
imagecopy($image, $temp_image, $max_x - $x, 0, 0, 0, 1, $sy);
544+
}
545+
break;
546+
}
547+
case IMG_FLIP_VERTICAL: {
548+
$sx = imagesx($image);
549+
$max_y = imagesy($image) - 1;
550+
$half_y = $max_y / 2;
551+
$temp_image = imageistruecolor($image)? imagecreatetruecolor($sx, 1): imagecreate($sx, 1);
552+
for ($y = 0; $y < $half_y; ++$y) {
553+
imagecopy($temp_image, $image, 0, 0, 0, $y, $sx, 1);
554+
imagecopy($image, $image, 0, $y, 0, $max_y - $y, $sx, 1);
555+
imagecopy($image, $temp_image, 0, $max_y - $y, 0, 0, $sx, 1);
556+
}
557+
break;
558+
}
559+
case IMG_FLIP_BOTH: {
560+
$sx = imagesx($image);
561+
$sy = imagesy($image);
562+
$temp_image = imagerotate($image, 180, 0);
563+
imagecopy($image, $temp_image, 0, 0, 0, 0, $sx, $sy);
564+
break;
565+
}
566+
default: {
567+
return;
568+
}
569+
}
570+
imagedestroy($temp_image);
571+
}
572+
}

0 commit comments

Comments
 (0)