Home » Php » php – How to use imagick's writeImage() function?

php – How to use imagick's writeImage() function?

Posted by: admin July 12, 2020 Leave a comment

Questions:

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');
How to&Answers:

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);