一,如何查看图片的dpi?
[lhdop@blog test3]$ identify -verbose 8.jpg
Image: 8.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1333x1867+0+0
Resolution: 150x150
Print size: 8.88667x12.4467
Units: PixelsPerInch
Colorspace: sRGB
Type: TrueColor
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 2488711
Red:
min: 0 (0)
max: 255 (1)
mean: 172.019 (0.674585)
standard deviation: 61.9397 (0.242901)
kurtosis: -0.690127
skewness: -0.678042
entropy: 0.912948
Green:
min: 0 (0)
max: 255 (1)
mean: 137.225 (0.538138)
standard deviation: 66.6771 (0.261479)
kurtosis: -1.17921
skewness: -0.0919349
entropy: 0.923473
Blue:
min: 0 (0)
max: 255 (1)
mean: 93.0464 (0.364888)
standard deviation: 74.6528 (0.292756)
kurtosis: -1.29616
skewness: 0.574976
entropy: 0.879247
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 134.097 (0.52587)
standard deviation: 67.7565 (0.265712)
kurtosis: -1.40475
skewness: -0.134471
entropy: 0.905222
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1333x1867+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 92
Orientation: Undefined
Profiles:
Profile-8bim: 28 bytes
Profile-icc: 3144 bytes
Properties:
date:create: 2022-04-26T00:42:59+00:00
date:modify: 2020-08-18T03:12:51+00:00
icc:copyright: Copyright (c) 1998 Hewlett-Packard Company
icc:description: sRGB IEC61966-2.1
icc:manufacturer: IEC http://www.iec.ch
icc:model: IEC 61966-2.1 Default RGB colour space - sRGB
jpeg:colorspace: 2
jpeg:sampling-factor: 1x1,1x1,1x1
signature: cc865a4d4f34d8ebe21978885849dfe3d98f06b501fe140c8f265f0344a891a4
Artifacts:
filename: 8.jpg
verbose: true
Tainted: False
Filesize: 1.13321MiB
Number pixels: 2.48871M
Pixels per second: 65.5681MB
User time: 0.030u
Elapsed time: 0:01.037
Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org
可以看到dpi:
Resolution: 150x150
两个150分别是水平和垂直方向的分辨率
只查看图片的宽高:
[lhdop@blog test3]$ identify 8.jpg
8.jpg JPEG 1333x1867 1333x1867+0+0 8-bit sRGB 1.13321MiB 0.000u 0:00.000
也可以用软件查看,例如 XnViewMp:
说明:刘宏缔的架构森林是一个专注架构的博客,
网站:https://blog.imgtouch.com本文: https://blog.imgtouch.com/index.php/2023/06/01/imagemagick-xiu-gai-tu-pian-de-dpi-fen-bian-lyu-resolution/
对应的源码可以访问这里获取: https://github.com/liuhongdi/ 或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,用convert修改dpi
1,从命令行修改
[lhdop@blog test3]$ convert 8.jpg -density 300 8_300.jpg
2,修改后查看dpi:
[lhdop@blog test3]$ identify -verbose 8_300.jpg
Image: 8_300.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1333x1867+0+0
Resolution: 300x300
Print size: 4.44333x6.22333
Units: PixelsPerInch
Colorspace: sRGB
Type: TrueColor
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Pixels: 2488711
Red:
min: 0 (0)
max: 255 (1)
mean: 172.02 (0.674589)
standard deviation: 61.9966 (0.243124)
kurtosis: -0.685443
skewness: -0.680275
entropy: 0.913934
Green:
min: 0 (0)
max: 255 (1)
mean: 137.224 (0.538135)
standard deviation: 66.7195 (0.261645)
kurtosis: -1.17922
skewness: -0.0924288
entropy: 0.924804
Blue:
min: 0 (0)
max: 255 (1)
mean: 93.053 (0.364914)
standard deviation: 74.6826 (0.292873)
kurtosis: -1.29582
skewness: 0.575793
entropy: 0.8809
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 134.099 (0.525879)
standard deviation: 67.7996 (0.265881)
kurtosis: -1.40557
skewness: -0.134436
entropy: 0.906546
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 1333x1867+0+0
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 92
Orientation: Undefined
Profiles:
Profile-8bim: 28 bytes
Profile-icc: 3144 bytes
Properties:
date:create: 2022-06-04T08:01:33+00:00
date:modify: 2022-06-04T08:01:33+00:00
icc:copyright: Copyright (c) 1998 Hewlett-Packard Company
icc:description: sRGB IEC61966-2.1
icc:manufacturer: IEC http://www.iec.ch
icc:model: IEC 61966-2.1 Default RGB colour space - sRGB
jpeg:colorspace: 2
jpeg:sampling-factor: 1x1,1x1,1x1
signature: 26f0ecbbec90899865350b3e9ab5dc84b621cf047a0465ce5c06da8d85ffb06d
Artifacts:
filename: 8_300.jpg
verbose: true
Tainted: False
Filesize: 1.253MiB
Number pixels: 2.48871M
Pixels per second: 65.669MB
User time: 0.030u
Elapsed time: 0:01.037
Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org
可以看到:dpi已变为:
Resolution: 300x300
在本地用xnviewmp查看:
可以看到图片的dpi已修改为 300x300
总结:修改图片dpi后,图片的长宽没有变,
可以看到图片的打印尺寸发生了变化:
相同的长宽像素时,更高的DPI表现为物理尺寸更小 - 这个很好理解,同样多的像素点,由于DPI高,所以需要的物理尺寸更少
以上图为例:
高度为 1867, 1867/300 = 6.22英寸
1867/150 = 12.45英寸,
所以dpi越高,则打印尺寸越小
三,查看imagemagick的版本:
[lhdop@blog ~]$ identify -version
Version: ImageMagick 6.9.10-86 Q16 x86_64 2020-01-13 https://imagemagick.org
Copyright: © 1999-2020 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib gvc jbig jng jp2 jpeg lcms ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zlib