ImageMagick PHP Image Resizing Imagick with Canvas

<?php
    try{
        $width = 60;
        $height = 60;
        $image = 'ct.jpg';
        $im = new Imagick($image);
        $im->thumbnailImage($width, null );
	$canvas = new Imagick();
	$canvas->newImage($width, $height, 'white', 'jpg' );
	$geometry = $im->getImageGeometry();

	/* The overlay x and y coordinates */
	$x = ( $width - $geometry['width'] ) / 2;
	$y = ( $height - $geometry['height'] ) / 2;

	/* Composite on the canvas  */
	$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, $x, $y );

        /* Save image  */
        $canvas->writeImage( 'ct_th.jpg');
        /* Output the image*/
	header( "Content-Type: image/jpg" );
	echo $canvas;
       }
      catch(Exception $e)
      {
        echo $e->getMessage();
      }
?>

You may also like...