8

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');
  • Check the correct namespace, \Imagick if you're using a PSR convention. Or perhaps check case-sensitive names, 'Imagick' instead of 'imagick'. You could also refer to pathinfo(), file_exists(), is_writable() or dirname() with flags, to get proper paths and concatenate with filename. But either way you must set a base directory from which you point to all files. It's up to you. – Felix Aballi Jul 18 '17 at 14:57

1 Answers1

6

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);
Savid
  • 311
  • 1
  • 2
  • 4
  • Perhaps you should declare: $imagick= new Imagick('path/to/image'); $imagick->writeImage('path/to/image'); $imagick->close(); $imagick->destroy(); to release all resources. – Felix Aballi Jul 18 '17 at 14:59