我正在开发一个Web应用程序,目前正在从旧应用程序中迁移某些内容,但我讨厌必须打开图像编辑器来获取有关要迁移的图像的一些信息。像图像尺寸之类的东西。
我可以在Linux中使用命令行工具执行此类任务吗?
我正在开发一个Web应用程序,目前正在从旧应用程序中迁移某些内容,但我讨厌必须打开图像编辑器来获取有关要迁移的图像的一些信息。像图像尺寸之类的东西。
我可以在Linux中使用命令行工具执行此类任务吗?
Answers:
对于某些图像格式,您可以仅使用以下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软件包的一部分。
/dev/null是个争论吗
                    identify -format "%[EXIF:DateTimeOriginal]\n" foobar.jpg
                    file:不支持无附加参数显示JPEG的大小$ file foo.jpg回报  foo.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 72x72, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=1], baseline, precision 8, 120x120, frames 3
                    获取此信息的最佳方法是使用以下identify命令:
$ identify image.png
或仅尺寸属性
$ identify -format "%wx%h" photo.jpg
它是ImageMagick的一部分,您可以像这样在Ubuntu上安装它:
$ sudo apt-get install imagemagick
              -verbose标志。我需要找到DPI(在“分辨率”字段中)
                    72x72
                    exiv2是从图片文件获取信息的“工具”:
~$exiv2 myimage.jpg
输出:
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将提供更详细的信息。它通常在Linux上的标准存储库中,也可以通过OSX上的自制软件获得。
尝试例如在当前文件夹中运行:
mediainfo *
要么
mediainfo .
这两个命令都将显示当前文件夹和子文件夹中所有媒体文件的信息。
在当前文件夹(包括子文件夹)开始的所有JPG图像上显示信息:
find . -iname "*.jpg" -exec mediainfo {} \;
它也与音频和视频文件非常有用,因为它显示了所有的音频/视频流,编码algorythm,容器类型,FOURCC码,即比特率XVID,X264等等。
在标准存储库中,还有一个通常用于所有主要发行版的GUI。 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•查看主题-无法将单位设置为pixelperinch?。
identify -verbose是我发现的唯一报告JPG质量的工具。例如它会说Quality: 90。
                    我刚刚发现,通过在后台使用ImageMagick,更少的内容(具有lessfile / lesspipe)实际上可以显示图像信息:
sudo apt-get install imagemagick
less wallpaper.jpg
输出量
wallpaper.jpg JPEG 1920x1200 1920x1200+0+0 8-bit DirectClass 580KB 0.000u 0:00.000
              您可以使用 :
php -r "print_r(getimagesize('file:///archives/Picture/12 farvardin/20120331_013.jpg'));"
你也可以file://用http://
php -r "print_r(getimagesize(\$argv[1]));"
                    
identify应该改用imo