Skip to content

Instantly share code, notes, and snippets.

@gourneau
Created November 29, 2010 02:47
Show Gist options
  • Save gourneau/719534 to your computer and use it in GitHub Desktop.
Save gourneau/719534 to your computer and use it in GitHub Desktop.
Create a thumbnail or resize an image with Imagemagick in PHP
<?php
//Dynamically resize images
function thumb_create($file, $width , $height ) {
try
{
/*** the image file ***/
$image = $file;
/*** a new imagick object ***/
$im = new Imagick();
/*** ping the image ***/
$im->pingImage($image);
/*** read the image into the object ***/
$im->readImage( $image );
/*** thumbnail the image ***/
$im->thumbnailImage( $width, $height );
/*** Write the thumbnail to disk ***/
$im->writeImage( 'THUMB_'.$file );
/*** Free resources associated with the Imagick object ***/
$im->destroy();
return 'THUMB_'.$file;
}
catch(Exception $e)
{
print $e->getMessage();
return $file;
}
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment