0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

imagemagick 使用例

Last updated at Posted at 2024-12-15

概要

画像処理コマンド
(自分が使うパターンだけ日記)

環境

  • Ubuntu-22.04

導入

sudo apt install -y imagemagick-6.q16

画像フォーマット変換

拡張子で判別
convert in.jpg out.png 

拡大縮小

アスペクト比を維持する
convert in.png -resize 1180x1720 out.png # -resize Bi-Cubic補間
convert in.png -scale x1024 out.png      # -scale 縮小は画素平均、拡大はNearest Neighbor法
convert in.png -sample 200% out.png      # -sample Nearest Neighbor法(補完なし)
アスペクト比を維持しない
convert in.png -resize 1180x1720! out.png

切り出し

左半分(50%)
convert in.png -crop 50%x100%+0+0 out.png
余白削除 ※同色(10%ノイズ許容)画素からなる辺
convert in.png -fuzz 10% -trim out.png
例: in.pngの左約半分を切り出し、余白除去した、in.png.out.pngを生成
f='1.png'
convert "$f" -crop '47%x100%+0+0' -fuzz '10%' -trim "$f.out.png"

特定レイヤーだけ抽出

アルファチャネル抽出
convert in.png -alpha extract out.png
  • -alpha : 透明度

生成/タイル

黒地の画像
convert -size 640x480 xc:"#000000" black.png
白線を引く
convert black.png -stroke "#ffffff" -draw 'line 0,0 639,0' whiteline.png
画像を繰り返す
convert -size 2x2 xc:"#000000" -fill white -draw "point 0,0" 22w.png
convert -size 1200x1200 tile:22w.png mesh.png
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?