5k7
5k7

Reputation: 107

Crop and resize image with Image Magician

I'm using Image Magician to crop and resize images to exact size - 230 x 300px. About 90 % of images are resized and croped to exact size, but some of them not.

My code :

$magicianObj = new \Application\Model\ImageMagician($imageLocation);   
$magicianObj -> resizeImage(230, 300, 'crop');
$magicianObj -> saveImage($thumb2, 100);

Few examples of images which are not cropped and resized properly :

1) orginal size : 533x800 resized to : 229x373

2) orginal size : 567x850 resized to : 229x346

3) orginal size : 245x398 resized to : 229x373

Is there any option to resize and crop them to exact size ?

Upvotes: 1

Views: 1116

Answers (1)

danielspoa
danielspoa

Reputation: 36

I just had this problem, and couldn't find any other questions than this, so i think its worth.

for some reason it doesn't pass this check inside resizeImage function:

if (($optimalWidth >= $newWidth && $optimalHeight >= $newHeight)) { 
    $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
  }

It appears your optimal width is less than new width, its getting 229 (maybe 229.xxxx) as your optimal width and 230 is your new width(which is just your desired width). That's why it resizes but doesn't crop. However it may echo 230 (here its 899 but if i echo it writes 900), dont know why. Using ceil() when getting the values should solve it, just above the IF.

$optimalWidth  = ceil($dimensionsArray['optimalWidth']);
$optimalHeight = ceil($dimensionsArray['optimalHeight']);

Upvotes: 2

Related Questions