-
-
Save xkungfu/594ca5a9d0c67994d39f6b34f10b60ad to your computer and use it in GitHub Desktop.
Create a thumbnail or resize an image with Imagemagick in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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