简体   繁体   English

ImageMagick / PHP调整大小问题:图像不会调整大小,但安装了ImageMagick

[英]ImageMagick/PHP Resizing Issue: Image Wont Resize, but ImageMagick is installed

I am having an odd issue with ImageMagick. 我对ImageMagick有一个奇怪的问题。

In the same script, I have the following code: 在同一个脚本中,我有以下代码:

 $ct = system("convert -version");
 echo $ct;

And that displays the following response: 这会显示以下响应:

 Version: ImageMagick 6.6.0-4 2012-04-26 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC Features: OpenMP

However, when I attempt to do this: 但是,当我尝试这样做时:

 $ct2 = system("convert -resize 800x600 test-image.jpg test-image2.jpg", $retval);
 echo $retval;

It returns 1, but the image does not get resized. 它返回1,但图像不会调整大小。 Shouldn't a second image be created, resized, under the file name "test-image2.jpg"? 不应该在文件名“test-image2.jpg”下创建第二张图片,调整大小吗? I checked the directory permissions, and they're set to 0777, so that shouldn't be the issue. 我检查了目录权限,并将它们设置为0777,因此不应该是问题。 Any idea what could be going on here? 知道这可能会发生什么吗?

A return code of 1 is usually considered an error. 返回码1通常被视为错误。 0 means "no error occurred". 0表示“未发生错误”。

I think it is because you have your arguments in the wrong order. 我认为这是因为你的论点错误。 ImageMagick wants an input file, a bunch of operations and then an output file. ImageMagick想要一个输入文件,一堆操作然后输出文件。 Try to switch order on the arguments: 尝试切换参数的顺序:

convert test-image.jpg -resize 800x600 test-image2.jpg

A good idea is to check out the IMagick extension for PHP. 一个好主意是查看PHP的IMagick扩展。 It gives you an object-oriented interface to most of the ImageMagick functions. 它为大多数ImageMagick函数提供了面向对象的接口。

Try this to display the error: 试试这个来显示错误:

$array = array(); 
echo "<pre>"; 
exec("convert test-image.jpg -resize 800x600 test-image2.jpg 2>&1", $array);  
echo "<br>".print_r($array)."<br>";  
echo "</pre>";  

Also I use exec not system, as said above the filename should come straight after convert and I would not use - but _ instead. 另外我使用exec而不是系统,如上所述文件名应该在转换后直接进行,我不会使用 - 但是_而不是。

System outputs to the screen and exec does not so in your first code you should have been able to use this: 系统输出到屏幕和exec在你的第一个代码中不是这样你应该能够使用它:

system("convert -version"); 

Try this and see what the path to IM is and try changing convert to the path which will probably be something like /usr/local/bin/convert 试试这个,看看IM的路径是什么,并尝试将转换为路径,这可能是/ usr / local / bin / convert

echo "<pre>";
system("type convert"); 
echo "</pre>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM