本文介绍了如何阻止Image Magick stripImage()删除分辨率数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将图片上传到我的网站,并使用Image Magick的stripImage()函数删除EXIF数据进行优化。

I'm uploading images to my website and optimising them by removing EXIF data using Image Magick's stripImage() function.

$img = new Imagick($image);
$img->stripImage();
$img->writeImage($image);
$img->destroy();

它工作得很好,我按预期减小了文件大小。但是,如果我在Photoshop中打开图像,Photoshop会将图像读取为每英寸1像素的分辨率。

It works quite well, I get reduced file sizes as expected. However, if I open the image in Photoshop, photoshop reads the image as having a resolution of 1 Pixel per Inch.

看来stripImage正在删除那个photoshop的EXIF数据用于确定分辨率。

It seems that stripImage is removing the EXIF data that photoshop uses to determine resolution.

如何在剥离其他所有内容时阻止此行为?

How do I prevent this behaviour while stripping everything else?

推荐答案

简短的回答是我认为你不能用ImageMagick有选择地删除部分EXIF数据,所以你可能需要提取原始密度,清除EXIF,然后放回Photoshop需要的任何东西。 ..但不确定,如果Photoshop使用JPEG标题中的标准密度或EXIF数据中的值。

The short answer is that I don't think you can selectively remove parts of the EXIF data with ImageMagick, so you will probably need to extract the original density, clear the EXIF, then put back whatever Photoshop needs... not sure though, if Photoshop uses the standard density in a JPEG header or a value from the EXIF data.

无论如何,为了得出答案,你可以得到图像中的所有密度类型设置 EXIFtool ,如下所示:

Anyway, to work out the answer, you can get all density type settings in an image with EXIFtool like this:

exiftool "-*resolution*"  image.jpg
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches

描述了Exiftool 。或者,如您所知,并且喜欢ImageMagick,您可以使用识别,如下所示:

Exiftool is described here. Or, as you know, and love ImageMagick, you can use identify like this:

identify -verbose IMG_3942.JPG | grep -i reso
  Resolution: 72x72
    exif:ResolutionUnit: 2
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:XResolution: 72/1
    exif:YResolution: 72/1

您也可以在剥离EXIF数据后使用ImageMagick设置密度:

You can also set the density with ImageMagick after you have stripped the EXIF data like this:

# Strip EXIF then add in resolution
convert IMG_3942.JPG -strip -density 180x180 180.jpg

# Check what happened
exiftool "-*resolution*"  180.JPG
Resolution Unit                 : inches
X Resolution                    : 180
Y Resolution                    : 180

如果你看。

You can also modify the EXIF data with libexif if you look here.

这篇关于如何阻止Image Magick stripImage()删除分辨率数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 05:26