Php 如何阻止Image Magick stripImage()删除分辨率数据

Php 如何阻止Image Magick stripImage()删除分辨率数据,php,image,imagemagick,photoshop,Php,Image,Imagemagick,Photoshop,我正在将图像上传到我的网站,并通过使用Image Magick的stripImage()函数删除EXIF数据对其进行优化 $img = new Imagick($image); $img->stripImage(); $img->writeImage($image); $img->destroy(); 它工作得很好,我得到了预期的文件大小减少。但是,如果我在Photoshop中打开图像,Photoshop会将图像读取为分辨率为每英寸1像素 stripImage似乎正在删除ph

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

$img = new Imagick($image);
$img->stripImage();
$img->writeImage($image);
$img->destroy();
它工作得很好,我得到了预期的文件大小减少。但是,如果我在Photoshop中打开图像,Photoshop会将图像读取为分辨率为每英寸1像素

stripImage似乎正在删除photoshop用来确定分辨率的EXIF数据


如何在剥离所有其他内容的同时防止这种行为?

简短的回答是,我认为您无法使用ImageMagick选择性地删除部分EXIF数据,因此您可能需要提取原始密度,清除EXIF,然后放回Photoshop所需的任何内容。。。但不确定Photoshop是否在JPEG头中使用标准密度或EXIF数据中的值

无论如何,要找到答案,您可以使用
EXIFtool
获得图像中的所有密度类型设置,如下所示:

exiftool "-*resolution*"  image.jpg
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
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
# 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
描述了Exiftool。或者,正如您所知,您也喜欢ImageMagick,您可以像这样使用
identify

exiftool "-*resolution*"  image.jpg
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
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
# 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
在剥离EXIF数据后,也可以使用ImageMagick设置密度,如下所示:

exiftool "-*resolution*"  image.jpg
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
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
# 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
如果查看,还可以使用
libexif
修改EXIF数据