PHP: Converting Image to TIFF with imagemagick
I am trying to convert and image to a tiff using imagemagick but am running into a problem when trying to write the file. I get an error that says:
Unable to open image... error/blob.c/OpenBlob/2584'
This is the code I am using:
$im2 = new Imagick($image);
$im2->setImageFormat("tiff");
$im2->setImageColorSpace(5);
$im2->writeImage("test.tiff");
$image is just a url I am passing to an image file. I am just running a simple test function to get it to work and put a test.tiff in the same folder. What could I be doing wron开发者_运维知识库g here? Having trouble finding much documentation on this.
Imagick works with local files and remote files.
$im2 = new Imagick($image);
$im2->setImageFormat("tiff");
$im2->setImageColorSpace(5);
$im2->writeImage("test.tiff");
It would work equally well in both remote and local server. The pfunc already said is permissions error. Another case that this error occurs is the definition of the directory incorrectly. sorry my en
The argument of the Imagick
constructor is to load a local image file. To load a remote image file, you should instantiate an Imagick
object without arguments and either:
- download the image content and pass it to the
readImageBlob
method, or fopen
the URL and pass it to thereadImageFile
method.
For example:
// assuming $image is an URL or path to a local file
$handle = fopen($image, 'rb');
$im2 = new Imagick();
$im2->readImageFile($handle);
$im2->setImageFormat("tiff");
$im2->setImageColorSpace(5);
$im2->writeImage("test.tiff");
fclose($handle);
$im2->destroy();
精彩评论