- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个保存 TIFF 图像的服务器。大多数客户端可以读取和显示 TIFF 图像,所以没有问题。但是,有些客户端不能处理这种格式,但可以处理 JPG。
我想到了使用 PHP 的 GD 库为没有 TIFF 读取能力的客户端进行服务器端转换。但我注意到 GD 也无法读取 TIFF 文件。
Imagick 不能在 Windows 中工作,我的想法是创建一个 imageFetcher.php,它将客户端想要的实际图像作为参数。它检查客户端的类型,并在需要时转换图像并输出 JPG,否则它只输出 TIFF。
有没有人知道我怎么做这样的事情?
提前致谢。
最佳答案
在论坛中 http://www.php.net/gd评论如下:
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(不会以像素为单位更改图像大小)
<?php
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<br />";
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<br />";
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<br /> x_res=$x_res $units - y_res=$y_res $units<br />";
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 "<img src=\"http://localhost/$file\" width=\"$width\" height=\"$height\" alt=\"getimagesize() example\" />";
echo "<br />$file => width=$width - height=$height - type=$type - attr=$attr<br /><br />";
$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 "<img src=\"http://localhost/$file\" width=\"$width\" height=\"$height\" alt=\"getimagesize() example\" />";
echo "<br />$file => width=$width - height=$height - type=$type - attr=$attr<br /><br />";
?>
$image = new Imagick('something.tiff');
$image->setImageFormat('png');
echo $image;
$image->writeImage('something.png');
关于php - 在php中将tiff转换为jpg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14342355/
我的目录中有一堆图像(100+),它们的名称都不同。有什么方法可以将它们重命名为 0.jpg、1.jpg、2.jpg 等,可能使用脚本(我运行的是 Windows),而不必单独重命名每个文件?如果在
文件的顺序由可以嵌入文件名中的数字确定,但有时嵌入在名称的开头,例如文件1.txt文件2.txt文件3.txt文件10.txt文件11.txtETC..或者1.txt2.txt10.txt等. 重命名
我有一个 inotify 等待脚本,只要检测到文件已上传到源目录,它就会将文件从一个位置移动到另一个位置。 我面临的挑战是我需要保留文件的基本名称并将以下扩展名:.JPEG、.JPG、.jpeg 转换
我有一段代码可以上传图像并创建缩略图,只要扩展名是小写的 jpg,但如果是大写的 JPG,它就不会上传图像。当我重命名图像时,例如example.JPG 到 example.jpg,它会上传。但是 e
我必须缩小和解压缩一组大小为 4608 x 3456 的 JPG 图像。目前,我已经能够将图像正确解压缩为 RGB 格式并将它们转换为位图。 现在我需要实现缩小,根据我目前所读到的正确缩小图像的内容,
这个问题困扰我好久了。我正在尝试在 PHP 中加载图像,但是有 jpg 和 JPG 图像,当我尝试通过 jpg 加载图像时,找不到 JPG 图像(显然) $img1 = ''; $img2 = '';
我使用这个函数来检测我的文件是否存在。虽然我有一些图像存储为 .jpg、.JPG、.png 和 .PNG。但即使真实文件的扩展名为 .JPG 或 .PNG,它也总是将 .jpg 或 .png 返回为真
我有很多这样的文件: 13040-3BLK1.JPG 13040-3NAV11.JPG 13040-50NAV11.JPG 13040-60NAV11.JPG 13040-LNAV1.JPG
我在机器人上安装了摄像头。长话短说,相机输出二进制数组,我相信这是一个 JPG 编码流。我这么说是因为我使用的库中的许多方法都暗示它是 JPG 编码的,并且第一个和最后 2 个字节是 255 216
我正在制作个人网页,我已将其草稿上传到 www.kurtpeek.com。我注意到的一个错误是,我在“关于我”部分中的一张 jpeg 图片“MIT_IAP_SAR_smallest.JPG”没有出现在
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关闭 9 年前。 要求提供代码的问题必须表现出对所解决问题的最低限度的理解。包括尝试过的解决方案、为什么
我有一张图片列表,我想将它们组合成每组一张图片。每个图像都有一个名称以及它是什么类型的图表。我希望有一种方法可以使用名称对图像进行分组,并为每个组返回单个 jpg 或 png 的输出。组合后的图像如下
我通过 JavaScript 设置 img 的 src 属性,如下所示: var newimgid = "images/" + fldrid + "/" + id + ".jpg"; document
我有一个 TImage,它显示文件夹中的 JPG 图像。每个 JPG 图像名称都是数字(例如 5968.jpg)。如果 JPG 图像不存在,我当前加载模板 JPG。 但是,我想在检查本地文件夹后再检查
我的脚本很简单。 SELECT file_name FROM images WHERE `id` = '$id' AND `file_name` LIKE '%_1.jpg' 当我在 mysql 中运
我有一个页面显示了一些产品,例如:- 标题- 描述- 图片 当图像存储在表中时,其存储为例如“image.jpg”...但是我想在上传图像时制作图像名称的标题将用作图像的标题产品的 html 标题(t
我想创建一个按钮来在 a.jpg 和 b.jpg 之间反复翻转图像。这是我的代码: function changeImg() { document.getElementById("
有没有人为 Windows 制作一个简单的 DLL,这样我就可以将原始图像数据保存为 JPG 格式?它也应该有 .lib 和 .h 文件,所以我不需要搞乱源代码编译,因为我发现它非常困难。 需要考虑的
我有一张我正在尝试创建的动态图像,它以前在一个网络主机上工作,直到我发现他们删除了一些功能,其中一些破坏了我的形象。我最近搬到了 hostgator,我也无法让图像在他们的网站上工作。实际的 PHP
有时我将 JPG 图像保存为未压缩的位图 (BMP/PNG),以在更改图像时保持质量。 我想知道,理论上是否可以将位图重新编码回其原始 JPG 格式,而不会损失任何质量(我编辑的区域除外)? 编辑:我
我是一名优秀的程序员,十分优秀!