This function works perfect.
/*******
Make thumbnail based on width
twidth: the width
from_dir: where to pull original from
to_dir: where to save resized image to
name: name of file
prefix: (optional) add a prefix to file name so 'temp_image.jpg' instead of 'image.jpg'
resource: (optional) the resource of a previously modified image to use instead of from_dir
*******/
function make_thumb ($twidth, $from_dir, $to_dir, $name, $prefix='', $source='')
{
$from = $from_dir.$name; //path of source image
$to = $to_dir.$prefix.$name; //path of destination
$size = GetImageSize($from); //size of source
$dest = getHorizontalProp($size, $twidth); //returns array of new dimensions
$dest_x = $dest['x'];
$dest_y = $dest['y'];
if ($resource != 0) {
$original = $resource;
} else {
$original = NewMagickWand() or die("Unable to create wand (MT)"); //create wand
MagickReadImage( $original, $from ) or die("Unable to ead source image (MT)"); //read source image
}
$transSize = MagickTransformImage( $original, '0x0', $dest_x.'x'.$dest_y ) or die("Unable to resize image (MT)"); //resize image
MagickWriteImage($transSize, $to) or die("Unable to save resized image (MT)"); //save resized image
DestroyMagickWand($transSize) or die("Unable to destroy wand (MT)"); //destroy wand
return $transSize;
}
I don't know how I am returning $transSize after destroying the wand, but I can use the returned value to resize an image over and over again.
//source_id_original is defined above
make_thumb (200, $directory, $directory, $main, 'test_', $source_id_original); // this works
MagickCropImage( $source_id_original, $box_width, $box_height, $width_in, $height_in ); //this does not work (dimensions of crop also defined elsewhere)