PHP:使用imagemagick将图像转换为TIFF [英] PHP: Converting Image to TIFF with imagemagick
问题描述
我正在尝试使用imagemagick将图像转换为tiff,但在尝试编写文件时遇到了问题。我收到一条错误消息:
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:
无法打开图片...
error / blob.c / OpenBlob / 2584'
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只是我传递给图像文件的网址。我只是运行一个简单的测试函数来使它工作并将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.
推荐答案
Imagick的参数
构造函数是加载本地图像文件。要加载远程图像文件,您应该实例化一个没有参数的 Imagick
对象,并且:
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:
- 下载图片内容并将其传递给
readImageBlob
方法,或 -
fopen
URL并将其传递给readImageFile
方法。
- download the image content and pass it to the
readImageBlob
method, or fopen
the URL and pass it to thereadImageFile
method.
例如:
// 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();
这篇关于PHP:使用imagemagick将图像转换为TIFF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!