Search code examples
phpimagick

Cannot save thumbnail with Imagick


I'm trying to create a thumbnail of an image, however, I can display it just fine, but cannot save it.

For example:

$image = new Imagick("photo.png");
$image->thumbnailImage(100, 0);
header("Content-Type: image/png");
echo $image;

This will in fact display my image in its thumbnailed form. But if I instead try to save it using $image->writeImage("thumb_photo.png") the script appears to stop (I confirmed this just by putting echo Hello or whatever afterwards) and no files have been created.

I'm using this on a server with Debian Wheezy, nginx, and PHP setup. The directory and PHP files themselves are readable, writable and have execute permissions for both the images and PHP files themselves. The imagick module version is 3.10. The PHP version is 5.4.

If someone can tell me what the problem could be I would appreciate it.

EDIT: After getting the exception, I am presented with WriteBlob Failed "thumb_photo.png" @ error/png.c/MagickPNGErrorHandler/1728.

Another thing, apparently if I change the output from "thumb_photo.png" to "photo.png" it works, but overwrites my image, how could I get around this and two why would it let me overwrite my image but not create a new one?


Solution

  • Apparently I had forgotten to change the group to www-data on the document root of the path to my files. I also needed to add chmod -R g+s to it as well. Go figure.