【发布时间】:2012-09-20 13:40:46
【问题描述】:
我只是在学习 imagick,只是想看到它起作用。我的基本用法是创建缩略图和渲染 .ai 和 .psd 文件。
我的 phpinfo() 显示已安装 imagemagick。
我有这个从http://valokuva.org/?cat=1 得到的代码:
/* Create new object */
$im = new Imagick();
/* Create new checkerboard pattern */
$im->newPseudoImage(100, 100, "pattern:checkerboard");
/* Set the image format to png */
$im->setImageFormat('png');
/* Fill background area with transparent */
$im->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
/* Activate matte */
$im->setImageMatte(true);
/* Control points for the distortion */
$controlPoints = array( 10, 10,
10, 5,
10, $im->getImageHeight() - 20,
10, $im->getImageHeight() - 5,
$im->getImageWidth() - 10, 10,
$im->getImageWidth() - 10, 20,
$im->getImageWidth() - 10, $im->getImageHeight() - 10,
$im->getImageWidth() - 10, $im->getImageHeight() - 30);
/* Perform the distortion */
$im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
/* Ouput the image */
//header("Content-Type: image/png");
echo $im;
现在的代码只是在屏幕上打印字符,例如:
�PNG IHDRo�*��ybKGD����9�oFFs��������^�� pHYsHHF�k>3CIDATx���w�U���̽[�H!�� ��л(�BQ@�(E� ���" J�NQA�4)�{�=�R�e˽3�Ϭ$!�l�%�o~��Mٝ{��y� ������d��^'��I&7��}f���[��(�,����]lЍ����
如果我取消注释倒数第二行,它只会将我带到一个损坏的图像。
我需要做其他事情吗?也许解码和保存文件?也许我做错了。
【问题讨论】:
-
测试了该代码,工作正常,也许你想象的安装不正确。
-
为什么要注释掉标题?该输出表明没有标题。
-
或者更确切地说是浏览器将输出误解为文本。您是否有其他任何内容输出到浏览器,尤其是在图像、空白或其他任何内容的前面。
-
我将标题注释掉作为测试,因为它返回的只是一个损坏的图像。
-
好吧,我想通了。我在那个向浏览器输出文本的文件中做其他事情。一旦我把它放到一个独立的文件中,它就可以工作了。
标签: php image-processing imagemagick imagick