How to use imagick's writeImage() function?

TK123 picture TK123 · Dec 24, 2011 · Viewed 9.8k times · Source

This works if I keep the script in the same directory as the image being manipulated. And the resultant image "foo.jpg" is also generated in the same location.

<?php

$im = new imagick('image.jpg');
$im->thumbnailImage( 200, 0);
$im->writeImage("foo.jpg");

?>

But what if the script is in one location and the image I wish to work with is in another and the location I wish to save the thumbnail to is somewhere else, how to specify these paths?

Doing something like this doesn't work:

$im = new imagick('path/to/image.jpg');

Answer

Savid picture Savid · Dec 24, 2011

Might be some file system problem. Try and get a file pointer in php first and check for any problems

$fileHandle = fopen("path/to/image.jpg", "w");

You can then use Imagick function (version 6.3.6 or newer);

$im->writeImageFile($filehandle);