pfunc
pfunc

Reputation: 1305

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 wrong here? Having trouble finding much documentation on this.

Upvotes: 2

Views: 6542

Answers (2)

Roberto Lunelli
Roberto Lunelli

Reputation: 21

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

Upvotes: 2

scoffey
scoffey

Reputation: 4688

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 the readImageFile 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();

Upvotes: 0

Related Questions