0
我想使用php剪裁.tif格式圖像。 我已經做過,如果圖像是以.jpg,gif或png的格式,但我想裁剪一個.tif圖像的某些尺寸,即從200x200正確的完整圖像的1024x1024 .please考慮它是.tif格式。我想使用php剪裁.tif格式圖像
http://rkwebsolutions.in.md-16.webhostbox.net/check/8713855051.tif
我使用這個功能支持JPEG/PNG/GIF格式的圖片,但是無法裁剪的.tif圖像
function cropImage($source_image, $target_image, $crop_area)
{
// detect source image type from extension
$source_file_name = basename($source_image);
$source_image_type = substr($source_file_name, -3, 3);
// create an image resource from the 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 a blank image having the same width and height as the crop area
// this will be our cropped image
$cropped_image = imagecreatetruecolor($crop_area['width'], $crop_area['height']);
// copy the crop area from the source image to the 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 from extension
$target_file_name = basename($target_image);
$target_image_type = substr($target_file_name, -3, 3);
// save the cropped image to 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 the function to crop an 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);
任何人都可以幫助 在此先感謝。
如果不轉換爲jpg格式,將無法調整它大小嗎? – ashutosh 2013-05-14 08:27:50
也許有沒有轉換大小的方法。調整大小後,您仍然可以重新調整大小的JPG到TIFF如果你想 – Agrest 2013-05-14 08:34:13
我試圖轉換圖像,但似乎圖像imagemagic沒有安裝在我的服務器上,請你指導。 – ashutosh 2013-05-14 09:30:40