ImageMagick 6.5.4:调用未定义的方法Imagick :: readFromBlob()

时间:2013-08-25 14:17:15

标签: php imagemagick

尝试使用ImageMagick和PHP操作图像时发生此错误。这是代码:

<?php

require 'config.php';

// Variables
$x = (int) $_POST['x'];
$y = (int) $_POST['y'];

$width = (int) $_POST['width'];
$height = (int) $_POST['height'];

// Source
$pos = strpos($_POST['src'], 'base64,') + 7;
$contents = base64_decode(substr($_POST['src'], $pos));

// Mime types
$types = array(
    'jpg' => 'image/jpeg',
    'png' => 'image/png',
    'gif' => 'image/gif'
);

// Data
$data = array(
    'mime' => substr($_POST['src'], 5, $pos - 13)
);

$data['ext'] = array_search($data['mime'], $types);

if (!$data['ext']) {
    $data['ext'] = 'png';
}

// Image
$image = new Imagick;

$image->readFromBlob($contents);

if ($data['ext'] == 'gif') {
    $frames = $image->coalesceImages();
} else {
    $frames = array($image);
}

foreach ($frames as $frame) {
    $image->resizeImage($width, $height, Imagick::FILTER_CATROM, 0);
    $image->cropImage($config['width'], $config['height'], $x, $y);
}

// Save
$path = $config['saveas'];

foreach ($data as $key => $value) {
    $path = str_replace('{' . $key . '}', $value, $path);
}

$path = dirname(__FILE__) . '/../../' . $path;

$image->writeImage($path, $data['ext'] == 'gif');

echo json_encode(true);

这是来自phpinfo的信息:

  • 启用了imagick模块
  • imagick module version 3.1.0RC2
  • 想象类Imagick,ImagickDraw,ImagickPixel, ImagickPixelIterator
  • ImageMagick版本ImageMagick 6.5.4-7 2012-05-07 Q16 OpenMP

在chrome中使用F12并处理小图片时,这是我的错误:

AJAX错误AvatarChanger.js:354

<br />
<b>Fatal error</b>:  Call to undefined method Imagick::readFromBlob() in        <b>/home/solidarity/cog/avatar/php/done.php</b> on line <b>37</b><br />

如果此处有人可以提供帮助或有任何想法,请分享:)

1 个答案:

答案 0 :(得分:1)

没有readFromBlob方法(正如错误消息所示),请查看文档,然后您可以找到readImageBlob()