Solidarity
Solidarity

Reputation: 23

ImageMagick 6.5.4: Call to undefined method Imagick::readFromBlob()

I have got this error happening when trying to manipulate an image using ImageMagick and PHP. Here is the code:

<?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);

And here's the info from phpinfo:

When using F12 in chrome and going through the processing of a small image this is my error in it's entirety:

AJAX error 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 />

If anyone here can help or has any ideas, please share :)

Upvotes: 0

Views: 1678

Answers (1)

dev-null-dweller
dev-null-dweller

Reputation: 29482

There is no readFromBlob method (just as error message says), check out documentation and there you can find readImageBlob()

Upvotes: 1

Related Questions