resizing with php imagick

GreasyTony

New Member
I am uploading images and resizing them to 300x200 pixelsi'm using the imagick extension and specifically the adaptiveResizeImage() function.when uploaded using bestfit there is a lot of whitespace on the sides of the image (depending on portrait or landscape).what i'd rather it did was resize to fill the entire area (no whitespace) and crop the longer length (height or width), ie i'd rather lose some image than have whitespace.is there an easy way to do this with the imagick extension?EDIT: I managed to do what i needed, but there has to be a better way\[code\]header('Content-type: image/jpeg');// target sizes$target_width = 300 ;$target_height = 100 ;// create new image$image = new Imagick('test.jpg');// get current size and calculate diffences from target sizes$size = $image->getImageGeometry();$size['width_diff'] = $target_width/$size['width'] ;$size['height_diff'] = $target_height/$size['height'] ;// resize by smallest sizeif($size['width_diff']>=$size['height_diff']){ $width = $target_width ; $height = $size['height']*$size['width_diff'] ;}else{ $width = $size['width']*$size['height_diff'] ; $height = $target_height ;}// get offsets$x = ($width-$target_width)/2 ;$y = ($height-$target_height)/2 ;// resize and offset image$image->adaptiveResizeImage($width, $height) ;$image->extentImage($target_width, $target_height,-$x,-$y);// output and clean upecho $image ;$image->clear();$image->destroy();\[/code\]
 
Back
Top