I use this command to batch modify images for a site. They need to be this size to suit the theme.
Now I also want to use these images in Facebook Ads, but they have to be resized. The command I use (which works fine) is:
for i in `ls -1 *.jpg`; do convert $i -fuzz 10% -trim +repage -resize 980x1200 -background white -gravity center -extent 980x1200 $i; done
Now I need to make a PHP script that does the same, but also returns the image as response.
I came up with the following:
<?php
/* Create the object and read the image in */
$im = new Imagick("image.jpg");
/* Trim the image with 10% fuzz */
$im->trimImage(10);
/* Repage */
$im->setImagePage(0, 0, 0, 0);
/* Resize */
$im->resizeImage(1200,628,Imagick::FILTER_LANCZOS,0);
/* Add Borders*/
$im->setImageBackgroundColor('White');
$im->setGravity('Centre');
$im->setImageExtent(1200,628);
/* Output the image */
header("Content-Type: image/" . $im->getImageFormat());
echo $im;
?>
Unfortunately it doesn't seem to work. All it does is return a black rectangle (which looks like the right dimensions as used in the script).
print_r(Imagick::getVersion());tell you?echo $im. You should useecho $im->getimageblob();.