i want to crop a .tif format image using php -
i want crop .tif format image using php . have done if image in .jpg , gif or png format want crop .tif image dimensions i.e 200x200 right full image of 1024x1024.please consider .tif format .
http://rkwebsolutions.in.md-16.webhostbox.net/check/8713855051.tif
i use function jpeg/png/gif format image unable crop .tif image
function cropimage($source_image, $target_image, $crop_area) { // detect source image type extension $source_file_name = basename($source_image); $source_image_type = substr($source_file_name, -3, 3); // create image resource source image switch(strtolower($source_image_type)) { case 'jpg': $original_image = imagecreatefromjpeg($source_image); break; case 'gif': $original_image = imagecreatefromgif($source_image); break; case 'png': $original_image = imagecreatefrompng($source_image); break; default: trigger_error('cropimage(): invalid source image type', e_user_error); return false; } // create blank image having same width , height crop area // our cropped image $cropped_image = imagecreatetruecolor($crop_area['width'], $crop_area['height']); // copy crop area source image blank image created above imagecopy($cropped_image, $original_image, 0, 0, $crop_area['left'], $crop_area['top'], $crop_area['width'], $crop_area['height']); // detect target image type extension $target_file_name = basename($target_image); $target_image_type = substr($target_file_name, -3, 3); // save cropped image disk switch(strtolower($target_image_type)) { case 'jpg': imagejpeg($cropped_image, $target_image, 100); break; case 'gif': imagegif($cropped_image, $target_image); break; case 'png': imagepng($cropped_image, $target_image, 0); break; default: trigger_error('cropimage(): invalid target image type', e_user_error); imagedestroy($cropped_image); imagedestroy($original_image); return false; } // free resources imagedestroy($cropped_image); imagedestroy($original_image); return true; } // using function crop image $source_image = 'image.jpg'; $target_image = 'cropped_image.jpg'; $crop_area = array('top' => 100, 'left' => 100, 'height' => 300, 'width' => 300); cropimage($source_image, $target_image, $crop_area); can in advance.
you can convert image jpg first resize. example code if have imagemagic installed on server:
exec("convert /path/to/file.tiff /path/to/file.jpg", $err);
Comments
Post a Comment