コマンドラインで画像サイズや情報を取得するには? (How to get image size on command line.) - uehatsu's tech blog

ImageMagickのコマンドの中に"identify"というコマンドがあります。
このコマンドを使って、画像サイズや画像詳細が閲覧できます。
まだOS Xにインストールしていない場合は以下のエントリーを参考にインストールして下さい。

こちらはOS X用のドキュメントですが、他のLinuxディストロでもほぼ同じ動作をします。
単純な画像データを取得する
$ identify uehatsu.jpg
uehatsu.jpg JPEG 180x175 180x175+0+0 8-bit DirectClass 7.93KB 0.000u 0:00.000
もっとデータを詳細に見たい
$ identify -verbose uehatsu.jpg
Image: uehatsu.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 180x175+0+0
Resolution: 72x72
Print size: 2.5x2.43056
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
(中略)
Filesize: 7.93KB
Number pixels: 31.5K
Pixels per second: 0B
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.7.8-2 2012-07-11 Q16 http://www.imagemagick.org
フォーマットも変えられます。
$ identify -format "%w %h" uehatsu.jpg
180 175
多少、動作が遅いところが有りますが、とりあえず画像ファイルサイズが取得できました。
次回は、これらの情報を元に画像サイズ縮小に挑戦します。

-----

We can get image size on command line with ImageMagick "identify".
If you don't install ImageMagick, please install ImageMagick.
$ identify uehatsu.jpg
uehatsu.jpg JPEG 180x175 180x175+0+0 8-bit DirectClass 7.93KB 0.000u 0:00.000
You want more?!
$ identify -verbose uehatsu.jpg
Image: uehatsu.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 180x175+0+0
Resolution: 72x72
Print size: 2.5x2.43056
Units: PixelsPerInch
Type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
(...)
Filesize: 7.93KB
Number pixels: 31.5K
Pixels per second: 0B
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.7.8-2 2012-07-11 Q16 http://www.imagemagick.org
Output format?
$ identify -format "%w %h" uehatsu.jpg
180 175
Wow!!
 
カテゴリ

Who is uehatsu?

uehatsu

アーカイブ

Facebook page