2015年03月07日

Macで画像ファイルのサイズを変更する方法



Macで画像ファイルのサイズを変更したい場合に、Terminal.appを使ってコマンドラインツールで方法を記す。

/usr/bin/sipsを使うとファイルの操作ができる。"sips"は"scriptable image processing system"でラスター画像ファイルの情報を取得し、あるいは変更するためのツールです。

sipsコマンドは、画像情報を取得する -g -X -v -x、画像情報を操作する-s -dなどとともに、画像そのものを変更するオプションがあります。そのうち、-zオプションが画像サイズを変更するものです。


-z, --resampleHeightWidth pixelsH pixelsW
--resampleWidth pixelsW
--resampleHeight pixelsH
-Z, --resampleHeightWidthMax pixelsWH


他にも画像を回転させる -r, 領域を切り出す -c, アイコンを追加する -iがよく使いそうです。

例えば、file.pngというファイルがあってそれを高さ128、幅128ピクセルのアイコンicon.pngにしたいと思ったら以下のようにします;


$ sips -z 128 128 file.png --out icon.png


"--out"で出力ファイルを指定しない場合には入力ファイルが上書き変更されます。

iOSアプリの開発で複数サイズのアイコンが必要ですが、大きなサイズのアイコンを一つ作りそれの複数サイズをこのコマンドで縮小して作るなんて使い方で使う場合には、以下のようにスクリプトを書くと簡単に一括作成できます。


一応、Mac OS X Yosemite 10.10.2でのヘルプを残しておきます。


Dune:tmp me$ sips -h
sips 10.4.4 - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

Usages:
sips [-h, --help]
sips [-H, --helpProperties]

sips [image-query-functions] imagefile ...

sips [profile-query-functions] profile ...

sips [image modification functions] imagefile ...
[--out result-file-or-dir]

sips [profile modification functions] profile ...
[--out result-file-or-dir]


Profile query functions:
-g, --getProperty key
-X, --extractTag tag tagFile
-v, --verify

Image query functions:
-g, --getProperty key
-x, --extractProfile profile

Profile modification functions:
-s, --setProperty key value
-d, --deleteProperty key
--deleteTag tag
--copyTag srcTag dstTag
--loadTag tag tagFile
--repair

Image modification functions:
-s, --setProperty key value
-d, --deleteProperty key
-e, --embedProfile profile
-E, --embedProfileIfNone profile
-m, --matchTo profile
-M, --matchToWithIntent profile intent
--deleteColorManagementProperties
-r, --rotate degreesCW
-f, --flip horizontal|vertical
-c, --cropToHeightWidth pixelsH pixelsW
-p, --padToHeightWidth pixelsH pixelsW
--padColor hexcolor
-z, --resampleHeightWidth pixelsH pixelsW
--resampleWidth pixelsW
--resampleHeight pixelsH
-Z, --resampleHeightWidthMax pixelsWH
-i, --addIcon
Dune:tmp me$ sips -H
sips 10.4.4 - scriptable image processing system.
This tool is used to query or modify raster image files and ColorSync ICC profiles.
Its functionality can also be used through the "Image Events" AppleScript suite.

The commands --getProperty, --setProperty, and --deleteProperty
can use one of the following keys as a parameter.

Special property keys:
all binary data
allxml binary data

Image property keys:
dpiHeight float
dpiWidth float
pixelHeight integer (read-only)
pixelWidth integer (read-only)
typeIdentifier string (read-only)
format string jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga
formatOptions string default | [low|normal|high|best|] | [lzw|packbits]
space string (read-only)
samplesPerPixel integer (read-only)
bitsPerSample integer (read-only)
creation string (read-only)
make string
model string
software string (read-only)
description string
copyright string
artist string
profile binary data
hasAlpha boolean (read-only)

Profile property keys:
description utf8 string
size integer (read-only)
cmm string
version string
class string (read-only)
space string (read-only)
pcs string (read-only)
creation string
platform string
quality string normal | draft | best
deviceManufacturer string
deviceModel integer
deviceAttributes0 integer
deviceAttributes1 integer
renderingIntent string perceptual | relative | saturation | absolute
creator string
copyright string
md5 string (read-only)

Dune:tmp me$

posted by 永遠製作所 at 02:16| 東京 ☔| Comment(0) | TrackBack(0) | Mac OS X | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント: [必須入力]

※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック
×

この広告は90日以上新しい記事の投稿がないブログに表示されております。