我正在尝试使用 imagemagick 的函数“thumbnailImage”调整图像大小。现在,我之后没有对图像进行任何操作,只是回显新的尺寸以查看它是否有效。到目前为止,它还不起作用。这是我的代码。注意:它确实呼应了原始尺寸,但不是新尺寸。
$image = $_FILES["file"]["tmp_name"];
//Get original dimensions
list($width, $height, $type, $attr) = getimagesize($image);
echo "<BR>";
echo "ORIGINAL:";
echo "<BR>";
echo "Image width $width";
echo "<BR>";
echo "Image height " .$height;
$max_height = 200;
$max_width = 150;
function thumbnail($image, $max_width, $max_height) {
$img = new Imagick($image);
$img->thumbnailImage($max_width, $max_height, TRUE);
return $img;
}
thumbnail($image, $max_width, $max_height);
//get new dimensions
list($width, $height, $type, $attr) = getimagesize($img);
echo "<BR>";
echo "NEW:";
echo "<BR>";
echo "Image width $width";
echo "<BR>";
echo "Image height " .$height;
它甚至没有显示第二组回声。现在有错误。
这段代码将起作用
$image = $_FILES["file"]["tmp_name"];
从您想要的任何地方获取文件等。您正在使用带有返回值的函数,但从未设置要返回的 var 。您还需要保存文件才能使用 getimagesize。
<?
// $image = $_FILES["file"]["tmp_name"]; // get the file from where ever you want etc
/*
you are using a function with a return value but never set up a var for it to return to
as well you need to save the file in order to use getimagesize
*/
$image = 'test.png';;
//Get original dimensions
list($width, $height, $type, $attr) = getimagesize($image);
echo "<BR>";
echo "ORIGINAL:";
echo "<BR>";
echo "Image width $width";
echo "<BR>";
echo "Image height " .$height;
$max_height = 200;
$max_width = 150;
function thumbnail($image, $max_width, $max_height) {
$img = new Imagick($image);
$img->thumbnailImage($max_width, $max_height, TRUE);
return $img;
}
// orginal line thumbnail($image, $max_width, $max_height);
$img=thumbnail($image, $max_width, $max_height);
file_put_contents('testmeResize.png',$img );
//get new dimensions
list($width, $height, $type, $attr) = getimagesize('testmeResize.png');
echo "<BR>";
echo "NEW:";
echo "<BR>";
echo "Image width $width";
echo "<BR>";
echo "Image height " .$height;
// we set it to display the image for proof it works etc
?>
<br>
<img alt="" src="testmeResize.png">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)