我正在开发一个网络应用程序,目前正在从一个旧的应用程序中迁移一些东西,但我讨厌我必须打开一个图像编辑器来获得一些关于我正在迁移的图像的信息。诸如图像尺寸之类的东西。
有什么命令行工具可以让我在Linux下完成这些任务吗?
对于一些图像格式,你可以直接使用file
命令。
$ file MyPNG.png
MyPNG.png: PNG image, 681 x 345, 8-bit/color RGB, non-interlaced
并非所有的图像格式都会报告尺寸(最明显的是JPEG不报告)。
$ file MyJpeg.jpg
MyJpeg.jpg: JPEG image data, JFIF standard 1.01
对于这些,你必须使用更详细的东西,比如。
$ convert MyJpeg.jpg -print "Size: %wx%h\n" /dev/null
Size: 380x380
convert
命令是ImageMagick软件包的一部分。
exiv2是"工具"。 用于从图片文件中获取信息。
~$exiv2 myimage.jpg
产出:{{{21112436}}
File name : myimage.jpg
File size : 1196944 Bytes
MIME type : image/jpeg
Image size : 2592 x 1944
Camera make : LG Electronics
Camera model : LG-P970
Image timestamp : 2013:05:19 17:27:06
Image number :
Exposure time : 1/9 s
Aperture :
Exposure bias : 0 EV
Flash : Yes, compulsory
Flash bias :
Focal length : 3.7 mm
Subject distance:
ISO speed : 745
Exposure mode :
Metering mode : Average
Macro mode :
Image quality :
Exif Resolution :
White balance : Auto
Thumbnail : image/jpeg, 13776 Bytes
Copyright :
Exif comment :
mediainfo][1]会给出更详细的信息。 它通常在 Linux 的标准仓库中,在 OSX 上也可以通过 homebrew 获得。
例如在当前文件夹中运行。
mediainfo *
或
mediainfo .
这两个命令将显示当前文件夹和子文件夹中所有媒体文件的信息。
显示从当前文件夹开始的所有JPG图像信息(包括子文件夹)。
find . -iname "*.jpg" -exec mediainfo {} \;
它对音频和视频文件也非常有用,因为它显示了所有音频/视频流的比特率、编码算法、容器类型、FOURCC代码,即:XVID
、X264
等。
XVID
、X264
等。
在所有主流发行版的标准仓库中也有一个图形用户界面,通常命名为 "mediainfo-gui"。
另外,可以看看Phil Harvey的ExifTool。 一个例子。
$ exiftool test.png
ExifTool Version Number : 8.15
File Name : test.png
Directory : .
File Size : 12 MB
File Modification Date/Time : 2014:02:13 13:04:52+01:00
File Permissions : rw-r--r--
File Type : PNG
MIME Type : image/png
Image Width : 2490
Image Height : 3424
Bit Depth : 8
Color Type : RGB
Compression : Deflate/Inflate
Filter : Adaptive
Interlace : Noninterlaced
Significant Bits : 8 8 8
Image Size : 2490x3424
另外,我想从命令行中获取dpi/分辨率的信息。 有趣的是,有时这些工具都不会在图像中报告这些信息(就像上面的片段)。 更多信息,请参见我想用Imagemagick改变DPI,而不改变图像数据的实际字节大小--超级用户--然而,"identify -verbose "似乎对前面的代码段中的同一图像有效。
$ identify -verbose test.png
Image: test.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 2490x3424+0+0
Resolution: 72x72
Print size: 34.5833x47.5556
Units: Undefined
Type: TrueColor
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
Channel statistics:
Red:
min: 8 (0.0313725)
max: 255 (1)
mean: 237.541 (0.931533)
standard deviation: 37.2797 (0.146195)
kurtosis: 21.2876
skewness: -4.56853
Green:
min: 15 (0.0588235)
max: 255 (1)
mean: 240.007 (0.941204)
standard deviation: 37.8264 (0.148339)
kurtosis: 20.7241
skewness: -4.51584
Blue:
min: 9 (0.0352941)
max: 255 (1)
mean: 240.349 (0.942547)
standard deviation: 38.7118 (0.151811)
kurtosis: 22.255
skewness: -4.72275
Image statistics:
Overall:
min: 8 (0.0313725)
max: 255 (1)
mean: 179.474 (0.703821)
standard deviation: 108.711 (0.426316)
kurtosis: -0.958865
skewness: -0.995795
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgb(223,223,223)
Matte color: grey74
Transparent color: black
Compose: Over
Page geometry: 2490x3424+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2014-02-13T13:11:08+01:00
date:modify: 2014-02-13T13:04:52+01:00
signature: bada990d3ba29b311501146d9013d67cf36f667c6d39b1f28a72ce913924397d
Artifacts:
verbose: true
Tainted: False
Filesize: 12.52MB
Number pixels: 8.526M
Pixels per second: 7.894M
User time: 1.080u
Elapsed time: 0:02.080
Version: ImageMagick 6.6.2-6 2012-08-17 Q16 http://www.imagemagick.org
...
虽然,使用identify -verbose
来读取PixelsPerInch单位的分辨率可能会有点棘手--请参见ImageMagick - View topic - Cannot set units to pixelsperinch?。