php tiff,在PHP中将tiff转换为jpg?
小編典典
IE不會顯示TIFF文件,并且標準的PHP發行版不支持與TIFF之間的轉換。
ImageMagick(http://www.imagemagick.org/script/index.php)是一個免費軟件,可以讀取,轉換和寫入多種格式的圖像。對于Windows用戶,它包括一個PHP擴展名php_magickwand_st.dll(是的,它在PHP
5.0.4下運行)。
從TIFF轉換為JPEG時,還必須從CMYK顏色空間轉換為RGB顏色空間,因為IE也無法顯示CMYK
JPG。請注意:-TIFF文件可能具有RGB或CMYK顏色空間-JPEG文件可能具有RGB或CMYK顏色空間
以下是使用ImageMagick擴展名的示例函數:-將TIFF轉換為JPEG文件格式-將CMIK轉換為RGB顏色空間-將圖像分辨率設置為300
DPI(不更改以像素為單位的圖像大小)
function cmyk2rgb($file) {
$mgck_wnd = NewMagickWand();
MagickReadImage($mgck_wnd, $file);
$img_colspc = MagickGetImageColorspace($mgck_wnd);
if ($img_colspc == MW_CMYKColorspace) {
echo "$file was in CMYK format
";
MagickSetImageColorspace($mgck_wnd, MW_RGBColorspace);
}
MagickWriteImage($mgck_wnd, str_replace('.', '-rgb.', $file));
}
function tiff2jpg($file) {
$mgck_wnd = NewMagickWand();
MagickReadImage($mgck_wnd, $file);
$img_colspc = MagickGetImageColorspace($mgck_wnd);
if ($img_colspc == MW_CMYKColorspace) {
echo "$file was in CMYK format
";
MagickSetImageColorspace($mgck_wnd, MW_RGBColorspace);
}
MagickSetImageFormat($mgck_wnd, 'JPG' );
MagickWriteImage($mgck_wnd, str_replace('.tif', '.jpg', $file));
}
function to300dpi($file) {
$mgck_wnd = NewMagickWand();
MagickReadImage($mgck_wnd, $file);
$img_units = MagickGetImageUnits($mgck_wnd);
switch ($img_units) {
case MW_UndefinedResolution: $units= 'undefined'; break;
case MW_PixelsPerInchResolution: $units= 'PPI'; break;
case MW_PixelsPerCentimeterResolution: $units= 'PPcm'; break;
}
list($x_res, $y_res) = MagickGetImageResolution($mgck_wnd);
echo "$file
 x_res=$x_res $units - y_res=$y_res $units
";
if($x_res == 300 && $y_res == 300 && $img_units == MW_PixelsPerInchResolution) {return; }
MagickSetImageResolution($mgck_wnd, 300 , 300);
MagickSetImageUnits($mgck_wnd, MW_PixelsPerInchResolution);
MagickWriteImage($mgck_wnd, str_replace('.', '-300.', $file));
}
$file='photos/test-cmyk.tif';
//this is a TIFF file in CMYK format with a 96 DPI resolution
cmyk2rgb($file);
$file = str_replace('.', '-rgb.', $file);
to300dpi($file);
$file = str_replace('.', '-300.', $file);
tiff2jpg($file);
$file = str_replace('.tif', '.jpg', $file);
to300dpi($file);
/* no file name changes as ImageMagick reports 300 DPIs
$file = str_replace('.', '-300.', $file);
*/
list($width, $height, $type, $attr) = getimagesize($file);
$width = $width/3;
$height = $height/3;
echo "";
echo "
$file => width=$width - height=$height - type=$type - attr=$attr
";
$file='photos/test-rgb.tif';
//this is a TIFF file in RGB format with a 96 DPI resolution
cmyk2rgb($file);
$file = str_replace('.', '-rgb.', $file);
to300dpi($file);
$file = str_replace('.', '-300.', $file);
tiff2jpg($file);
$file = str_replace('.tif', '.jpg', $file);
to300dpi($file);
/* no file name changes as ImageMagick reports 300 DPIs
$file = str_replace('.', '-300.', $file);
*/
list($width, $height, $type, $attr) = getimagesize($file);
$width = $width/3;
$height = $height/3;
echo "";
echo "
$file => width=$width - height=$height - type=$type - attr=$attr
";
?>
注意-盡管ImageMagick正確地將JPEG文件的分辨率設置為300 DPI,但是某些程序可能不會注意到它。
其他
使用“ imagick” PECL擴展名
根據源和目標(文件?URL?http響應?),您將執行以下操作:
$image = new Imagick('something.tiff');
$image->setImageFormat('png');
echo $image;
要么
$image->writeImage('something.png');
2020-05-29
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php tiff,在PHP中将tiff转换为jpg?的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 长安汽车:2023 年将实现更多新技术量
- 下一篇: 微软 Phil Spencer:如果成功
