日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php tiff,在PHP中将tiff转换为jpg?

發布時間:2023/12/19 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。