I'm trying to do the following in iMagick and I can't get it to work:
Check if image is over 390 pixels high, if it is then resize it to 390 pixels high, if it isn't keep the dimensions.
Add a white canvas, 300px wide by 400px high and then place the image into the center of that.
My Code is:
$im = new imagick("test.jpg");
$imageprops = $im->getImageGeometry();
$width = $imageprops['width'];
$height = $imageprops['height'];
if($height > '390'){
$newHeight = 390;
$newWidth = (390 / $height) * $width;
}else{
$newWidth = $imageprops['width'];
$newHeight = $imageprops['height'];
}
$im->resizeImage($newWidth,$newHeight, imagick::FILTER_LANCZOS, 0.9, true);
$canvas = new Imagick();
$canvas->newImage(300, 400, 'white', 'jpg' );
$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, 100, 50 );
$canvas->writeImage( "test-1.jpg" );
When the images are produced the large ones are scaled to 388 pixels high for some reason and the small ones are left to their original dimensions.
The placing on the canvas is always incorrect although does work on the large images with 100,50 added to the composite image.
Most of the images are tall and thin however there are a few that are wider than they are tall.
Any ideas where I am going wrong ?
Thanks,
Rick