Running Imagick from alternative binary at usr/bin

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
joakimvr
Posts: 1
Joined: 2015-08-12T04:47:37-07:00
Authentication code: 1151

Running Imagick from alternative binary at usr/bin

Post by joakimvr »

Hi guys!

I recently moved host, and I'm having some trouble running Imagick as it's installed differently from my previous host. I have attached the PHP code that worked on my old host;

From the file functions.php

Code: Select all

function thumb_create($file, $width , $height, $output) {
	try  {
	$thumb_dir = "thumb/";
	$image = $file;
        $im = new Imagick();
	$im->pingImage($image);
	$im->readImage( $image );
	$im->thumbnailImage( $width, $height );
	$im->writeImage( 'THUMB_'.$output );
	rename ('THUMB_'.$output, $thumb_dir . $output);
	$im->destroy();
	return 'THUMB_'.$output;
	}
	catch(Exception $e)
	{
	print $e->getMessage();
	return $file;
	}};
Now, after transfering my site to Siteground I get this error;
Fatal error: Class 'Imagick' not found in /home/sitename/public_html/php/includes/functions.php on line 204
Someone from their support team told me the default imagick extension is not enabled and doesn't work on their shared servers, but I could use this alternative binary;
https://www.siteground.com/kb/what_is_t ... agemagick/

Does anyone have any suggestions as to how I could get this code working with possibly keeping the same syntax as before in the thumb_create PHP function? I'm sure the fix is quite simple, but I can't seem to get it working, and I have little experience with server folders and binaries. Any help would be highly appriciated!

Best regards,
Joakim
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Running Imagick from alternative binary at usr/bin

Post by Bonzo »

As you already know Imagick is not installed and you have been recommended to run imagemagick from php and you will need to use exec( ). So the syntax is completely different. You can see some php Imagemagick examples following the link in my signature.

This will probably do what you want:

Code: Select all

$newFile = "thumb/".$output;
exec("convert $image -thumbnail {$width}x{$height} $newFile");
Post Reply