尝试使用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的信息:
在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 />
如果此处有人可以提供帮助或有任何想法,请分享:)