Imagecrop () alternative for PHP <5.5

A simple question motivated by curiosity, with a likely complex answer: is it possible to emulate the new PHP 5.5 imagecrop () in earlier versions, for example 5.4, by combining other GD functions?

Awn .. But without error imagecrop () of the black line .: P

+7
source share
1 answer

This should be a replacement for imagecrop() (no error ...):

 function mycrop($src, array $rect) { $dest = imagecreatetruecolor($rect['width'], $rect['height']); imagecopy( $dest, $src, 0, 0, $rect['x'], $rect['y'], $rect['width'], $rect['height'] ); return $dest; } 

Using:

 $img = mycrop($img, ['x' => 10, 'y' => 10, 'width' => 100, 'height' => 100]); 

Note that the error seems to be fixed in PHP 5.6.12 .

+16
source

All Articles