【问题标题】:php imagick resize image code not working properlyphp imagick调整图像代码无法正常工作
【发布时间】:2015-07-18 19:32:03
【问题描述】:

我正在使用以下 Imagick 函数来调整图像大小。代码运行并调整图像大小,但来自服务器的错误提示“从测试服务器请求文档时发生错误”。而且我无法检测到问题。然而,在浏览器中,它会输出非人类可读的字符。如果我尝试将调整大小/修改后的图像输出到浏览器,则没有问题。当我尝试将图像保存到磁盘时,我遇到了这个问题。

这是我的代码:

<?php

imagick_resize('running.jpg');

function imagick_resize($image, $width = 460, $height = 300)
{

// define widescreen dimensions
// $width = 460;
// $height = 300;

// load an image
$i = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/alchemyapi/' . $image);
// get the current image dimensions
$geo = $i->getImageGeometry();

// crop the image
if(($geo['width']/$width) < ($geo['height']/$height))
{
    $i->cropImage($geo['width'], floor($height*$geo['width']/$width), 0, (($geo['height']-($height*$geo['width']/$width))/2));
}
else
{
    $i->cropImage(ceil($width*$geo['height']/$height), $geo['height'], (($geo['width']-($width*$geo['height']/$height))/2), 0);
}
// thumbnail the image
$i->ThumbnailImage($width,$height,true);
// save or show or whatever the image
# $i->setImageFormat('png');
# header("Content-Type: image/png");
# unlink('small_square_img.png');
$i->writeImage($_SERVER['DOCUMENT_ROOT'] . '/alchemyapi/tmp/small_square_img.png'); 
# file_put_contents('small_square_img.png', $i);
exit($i);
}
?> 

【问题讨论】:

    标签: php imagick


    【解决方案1】:

    您发送到浏览器的数据不是有效的图像。在您的某些文件中很可能在

    如果发生,您应该检查并修复它,或者提供“非人类可读字符”的示例,以便人们了解问题所在。

    【讨论】:

      猜你喜欢
      • 2011-11-26
      • 2023-03-16
      • 1970-01-01
      • 2019-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多