LoginSignup
8
6

More than 1 year has passed since last update.

macOS の標準コマンドで Jpeg 画像を PNG に変換するワンライナー

Last updated at Posted at 2019-08-22

Jpg 画像を PNG 画像に変換したいが、標準コマンドで変換できないか。(brew も使わず、別途アプリも入れずに)

最近の Qiita 記事でもmac jpeg png 変換 コマンド」でググっても ImageMagick のリッチなのばかりでドンピシャな記事が出てこなかったので、自分のググラビリティとして。

  • 動作確認: macOS Mojave(OSX 10.14.6), Catalina(OSX 10.15.7)

TL; DR (今北産業)

  1. macOS 同梱の sips コマンドで変換可能です。
  2. 特定ファイルを変換(foo.jpg→foo.png)する例

    sips -s format png foo.jpg --out foo.png
    
  3. -s format png オプションで PNG を指定しています。

併せて読みたい

TS; DR

カレントディレクトリの画像をすべて1階層上のpngディレクトリに出力
sips -s format png *.* --out ../png
カレントにpngディレクトリを作成してpngに変換したjpg画像をそこに出力
mkdir png; sips -s format png *.jpg --out ./png

変換以外

画像情報を sips コマンドで取得する

画像の情報を取得する
$ sips -g all sample.jpg
/Users/admin/Desktop/sample.jpg
  pixelWidth: 256
  pixelHeight: 256
  typeIdentifier: public.png
  format: png
  formatOptions: default
  dpiWidth: 72.000
  dpiHeight: 72.000
  samplesPerPixel: 3
  bitsPerSample: 8
  hasAlpha: no
  space: RGB
  profile: sRGB IEC61966-2.1

sips コマンドでできること(ただのヘルプ)

  • Big Sur(OSX 10.16) では Javascript の項目が増えているそうです:関連 Qiita 記事
Mojaveのsipsコマンドヘルプ
$ sips --help
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 
    -o, --optimizeColorForSharing 
Catalinaのsipsコマンドヘルプ
$ sips --help
sips - 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 [image-functions] imagefile ... 
    sips [profile-functions] profile ... 

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

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

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

  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 
        --cropOffset offsetY offsetH 
    -p, --padToHeightWidth pixelsH pixelsW 
        --padColor hexcolor 
    -z, --resampleHeightWidth pixelsH pixelsW 
        --resampleWidth pixelsW 
        --resampleHeight pixelsH 
    -Z, --resampleHeightWidthMax pixelsWH 
    -i, --addIcon 
        --optimizeColorForSharing 
    -o, --out file-or-directory 
    -j, --js file 

  Other functions: 
        --debug           Enable debugging output
    -h, --help            Show help
    -H, --helpProperties  Show help for properties
        --man             Generate man pages
    -v, --version         Show the version
        --formats         Show the read/write formats

参考文献

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6