「ImageMagick」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(新規作成(英語版より))
 
(→‎See also: 翻訳)
 
(2人の利用者による、間の6版が非表示)
1行目: 1行目:
[[Category:Multimedia]]
+
[[Category:マルチメディア]]
 
[[de:ImageMagick]]
 
[[de:ImageMagick]]
 
[[en:ImageMagick]]
 
[[en:ImageMagick]]
 
[[es:ImageMagick]]
 
[[es:ImageMagick]]
  +
[[Wikipedia:ImageMagick|Wikipedia]] から:
{{Expansion|If these formats are disabled for libmagick by default, shouldn't they also be disabled for graphicsmagick by default?|section=graphicsmagick security and imagemagick security}}
 
According to [[Wikipedia:ImageMagick|Wikipedia]]:
 
   
  +
:ImageMagick は、ラスターイメージファイルとベクターイメージファイルを表示、変換、編集するための無料のオープンソースソフトウェアスイートです。200 を超える画像ファイル形式を読み書きできます。
:ImageMagick is a free and open-source software suite for displaying, converting, and editing raster image and vector image files. It can read and write over 200 image file formats.
 
   
  +
== インストール ==
{{Note|{{Pkg|imagemagick}} uses [[Ghostscript]] for PDF, EPS, PS and XPS parsing. Because there have been multiple vulnerabilities with Ghostscript[https://security.archlinux.org/package/ghostscript], it is compiled without Ghostscript library. It would fall back to {{ic|gs}} command instead, but that is, by default, disabled by the line {{hc|/etc/ImageMagick-7/policy.xml|2=<policy domain="delegate" rights="none" pattern="gs" />}}
 
See also {{Bug|59778}}, {{Bug|62171}}.
 
}}
 
   
  +
{{Pkg|imagemagick}} パッケージを [[インストール]] します。あるいは、API とコマンドラインインターフェイスの安定性を重視した ImageMagick のフォークである [[Wikipedia:GraphicsMagick|GraphicsMagick]] の {{Pkg|graphicsmagick}} をインストールします。
== Installation ==
 
   
  +
== 使い方 ==
[[Install]] the {{Pkg|imagemagick}} package. Alternatively install {{Pkg|graphicsmagick}} for [[Wikipedia:GraphicsMagick|GraphicsMagick]], a fork of ImageMagick, emphasizing stability of the API and command-line interface.
 
   
  +
GraphicsMagick については、{{man|1|ImageMagick}} または {{man|1|gm}} を参照してください。
== Usage ==
 
   
  +
{{Tip|公式 HTML ドキュメントは、パッケージをインストールするとローカルで利用できます:
See {{man|1|ImageMagick}}, or {{man|1|gm}} for GraphicsMagick.
 
  +
* ImageMagick で {{ic|/usr/share/doc/ImageMagick-7/www/index.html}}
  +
* GraphicsMagick で {{ic|/usr/share/doc/GraphicsMagick/www/index.html}}}}
   
  +
=== 共通操作 ===
Popular operations include {{ic|-append}}, {{ic|-resize}}, {{ic|-rotate}}, {{ic|-quality}} and many more. For example, to combine multiple pictures into one:
 
  +
  +
{{Note|オプションの前の記号は重要です。反対の操作は、''マイナス'' の代わりに ''プラス'' を使用して実行できます。}}
  +
  +
==== 画像形式間の変換 ====
  +
  +
この機能の基本的な使用法は、既存の希望する画像形式をファイル名拡張子として指定することです。たとえば、指定された ''.png'' 画像を ''.jpg'' にするには、次を使用します。
  +
  +
$ convert image.png image.jpg
  +
  +
==== 追加 ====
  +
  +
複数の写真を 1 つに結合する:
   
 
$ convert -append ''input.pngs'' ''output.png''
 
$ convert -append ''input.pngs'' ''output.png''
   
  +
==== トリミング、切り取り ====
{{Note|The sign before an option is important. Opposite operations can be performed by using a ''plus'' instead of a ''minus''.}}
 
   
  +
複数の画像の一部を切り取って別の形式に変換するには:
To crop part of multiple images and convert them to another format:
 
   
 
$ mogrify -crop ''WIDTH''x''HEIGHT''+''X''+''Y'' -format jpg *.png
 
$ mogrify -crop ''WIDTH''x''HEIGHT''+''X''+''Y'' -format jpg *.png
   
Where ''WIDTH'' and ''HEIGHT'' is the cropped output image size, and ''X'' and ''Y'' is the offset from the input image size.
+
ここで、''WIDTH'' ''HEIGHT'' はトリミングされた出力画像サイズ、''X'' ''Y'' は入力画像サイズからのオフセットです。
   
  +
また、重力を利用してそのエッジを選択し、画像から単一のエッジを切り取る {{ic|-chop}} こともできます。こちらの方が、数や試行錯誤が少なくて済むので簡単です。
=== Screenshot taking ===
 
   
  +
$ magick frame_red.gif -gravity South -chop 0x10 chop_bottom.gif
An easy way to take a screenshot of your current system is using the {{man|1|import}} command:
 
   
  +
==== ストレージサイズを制限する ====
$ import -window root screenshot.jpg
 
   
  +
特定のストレージサイズで適切な品質を達成するには、次の手順を実行します:
{{ic|import}} is part of the {{Pkg|imagemagick}} package.
 
   
  +
$ convert image.jpg -define jpeg:extent=3000KB image_small.jpg
Running {{ic|import}} without the {{ic|-window}} option allows selecting a window or an arbitrary region interactively. With {{ic|-pause}} you can specify a delay in which you can, for example, lower some windows.
 
   
  +
これにより変換時間が短縮されることを期待します。{{ic|-quality}} に注意してください。
{{Note|If you prefer '''graphicsmagick''' alternative, just prepend "gm", e.g. {{ic|$ gm import -window root screenshot.jpg}}.}}
 
   
  +
$ convert image.jpg -quality 85% image_small.jpg
==== Screenshot of multiple X screens ====
 
   
  +
品質とストレージサイズの相関関係が明確でない場合は、使用が難しくなります。
If you run twinview or dualhead, simply take the screenshot twice and use {{Ic|imagemagick}} to paste them together:
 
  +
  +
=== スクリーンショットの取得 ===
  +
  +
現在のシステムのスクリーンショットを撮る簡単な方法は、{{man|1|import}} コマンドを使用することです:
  +
  +
$ import -window root screenshot.jpg
  +
  +
{{ic|-window}} オプションを指定せずに {{ic|import}} を実行すると、ウィンドウまたは任意の領域を対話的に選択できます。{{ic|-pause}} を使用すると、たとえば一部のウィンドウを下げるなどの遅延を指定できます。
  +
  +
{{Note|'''graphicsmagick''' の代替手段を希望する場合は、"gm" を先頭に追加します (例:{{ic|$ gm import -window rootscreenshot.jpg}})}}
  +
  +
==== 複数の X 画面のスクリーンショット ====
  +
  +
Twinview または Dualhead を実行している場合は、スクリーンショットを 2 回取得し、{{ic|imagemagick}} を使用してそれらを貼り付けます:
   
 
{{bc|
 
{{bc|
import -window root -display :0.0 -screen /tmp/0.png
+
$ import -window root -display :0.0 -screen /tmp/0.png
import -window root -display :0.1 -screen /tmp/1.png
+
$ import -window root -display :0.1 -screen /tmp/1.png
convert +append /tmp/0.png /tmp/1.png screenshot.png
+
$ convert +append /tmp/0.png /tmp/1.png screenshot.png
rm /tmp/{0,1}.png
+
$ rm /tmp/{0,1}.png
 
}}
 
}}
   
==== Screenshot of individual Xinerama heads ====
+
==== 個々の Xinerama ヘッドのスクリーンショット ====
   
  +
Xinerama ベースのマルチヘッドセットアップには、仮想画面が 1 つだけあります。物理画面の高さが異なる場合、スクリーンショットにデッドスペースが発生します。この場合、各物理画面のスクリーンショットを個別に取得することができます。 Xinerama 情報が X サーバーから利用できる限り、以下は機能します:
Xinerama-based multi-head setups have only one virtual screen. If the physical screens are different in height, you will find dead space in the screenshot. In this case, you may want to take screenshot of each physical screen individually. As long as Xinerama information is available from the X server, the following will work:
 
   
 
{{bc|<nowiki>
 
{{bc|<nowiki>
67行目: 92行目:
 
</nowiki>}}
 
</nowiki>}}
   
  +
==== アクティブ/フォーカスされたウィンドウのスクリーンショット ====
==== Screenshot of the active/focused window ====
 
   
  +
次のスクリプトは、現在フォーカスされているウィンドウのスクリーンショットを取得します。EWMH/NetWM 互換の X ウィンドウマネージャーで動作します。以前のスクリーンショットが上書きされないように、現在の日付がファイル名として使用されます。
The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.
 
   
 
{{bc|<nowiki>
 
{{bc|<nowiki>
78行目: 103行目:
 
</nowiki>}}
 
</nowiki>}}
   
  +
あるいは、EWMH のサポートに関係なく、次のものが機能するはずです:
Alternatively, the following should work regardless of EWMH support:
 
   
 
$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
 
$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
   
  +
{{Note|一部のプログラム ([[zathura]] など) のスクリーンショットが空白で表示される場合は、{{ic|-frame}} を追加するか、{{ic|xdotool}} コマンドから {{ic|-f}} を削除してみてください。}}
{{Note|If screenshots of some programs ([[dwb]] and [[zathura]]) appear blank, try appending {{ic|-frame}} or removing {{ic|-f}} from the {{ic|xdotool}} command.}}
 
  +
  +
=== 画像データの暗号化 ===
  +
  +
暗号化するには:
  +
  +
$ echo ''pass_phrase'' | magick ''image.jpg'' -encipher - -depth 8 png24:''image.png''
  +
  +
これは次の方法で復号化できます:
  +
  +
$ echo ''pass_phrase'' | magick ''image.png'' -decipher - ''image.jpg''
  +
  +
このようなコマンドに関するあらゆる種類の問題や提案については、[https://imagemagick.org/Usage/transform/#encipher Encrypting Images] のディスカッションを読むことを強くお勧めします。
  +
  +
{{ic|cipher}} タグを持つ画像形式のメタデータは、暗号化のテストに使用できます。ただし、EXIF 編集プログラムによって削除または偽装される可能性があります。
  +
  +
$ identify -verbose image.png
  +
  +
一般に、ラスターイメージが暗号化されているかどうかのテストは、ピクセルコンポーネントの分布をチェックすることで実行できます。特定のしきい値を超える場合、データはランダムであると見なされ、暗号化の候補となる可能性があります。ただし、誤検知の例としては、[[wikipedia:Diamond-square algorithm|Diamond-square algorithm]] で作成された画像が挙げられます。
   
== See also ==
+
== 参照 ==
   
* [https://www.imagemagick.org/ ImageMagick website] for an extensive list of options and examples.
+
* [https://www.imagemagick.org/ ImageMagick Web サイト] には、[https://imagemagick.org/Usage/ サンプル] および [https://imagemagick.org/script/examples.php ショーケース] の広範なリストが掲載されています。
* [[List of applications/Multimedia#Image processing]]
+
* [[アプリケーション一覧#Image processing]]
  +
* [http://www.fmwconcepts.com/imagemagick/index.php Fred's ImageMagick Scripts] ImageMagic スクリプトの大規模なコレクション

2024年1月10日 (水) 00:42時点における最新版

Wikipedia から:

ImageMagick は、ラスターイメージファイルとベクターイメージファイルを表示、変換、編集するための無料のオープンソースソフトウェアスイートです。200 を超える画像ファイル形式を読み書きできます。

インストール

imagemagick パッケージを インストール します。あるいは、API とコマンドラインインターフェイスの安定性を重視した ImageMagick のフォークである GraphicsMagickgraphicsmagick をインストールします。

使い方

GraphicsMagick については、ImageMagick(1) または gm(1) を参照してください。

ヒント: 公式 HTML ドキュメントは、パッケージをインストールするとローカルで利用できます:
  • ImageMagick で /usr/share/doc/ImageMagick-7/www/index.html
  • GraphicsMagick で /usr/share/doc/GraphicsMagick/www/index.html

共通操作

ノート: オプションの前の記号は重要です。反対の操作は、マイナス の代わりに プラス を使用して実行できます。

画像形式間の変換

この機能の基本的な使用法は、既存の希望する画像形式をファイル名拡張子として指定することです。たとえば、指定された .png 画像を .jpg にするには、次を使用します。

$ convert image.png image.jpg

追加

複数の写真を 1 つに結合する:

$ convert -append input.pngs output.png

トリミング、切り取り

複数の画像の一部を切り取って別の形式に変換するには:

$ mogrify -crop WIDTHxHEIGHT+X+Y -format jpg *.png

ここで、WIDTHHEIGHT はトリミングされた出力画像サイズ、XY は入力画像サイズからのオフセットです。

また、重力を利用してそのエッジを選択し、画像から単一のエッジを切り取る -chop こともできます。こちらの方が、数や試行錯誤が少なくて済むので簡単です。

$ magick frame_red.gif -gravity South -chop 0x10 chop_bottom.gif

ストレージサイズを制限する

特定のストレージサイズで適切な品質を達成するには、次の手順を実行します:

$ convert image.jpg -define jpeg:extent=3000KB image_small.jpg

これにより変換時間が短縮されることを期待します。-quality に注意してください。

$ convert image.jpg -quality 85% image_small.jpg

品質とストレージサイズの相関関係が明確でない場合は、使用が難しくなります。

スクリーンショットの取得

現在のシステムのスクリーンショットを撮る簡単な方法は、import(1) コマンドを使用することです:

$ import -window root screenshot.jpg

-window オプションを指定せずに import を実行すると、ウィンドウまたは任意の領域を対話的に選択できます。-pause を使用すると、たとえば一部のウィンドウを下げるなどの遅延を指定できます。

ノート: graphicsmagick の代替手段を希望する場合は、"gm" を先頭に追加します (例:$ gm import -window rootscreenshot.jpg)

複数の X 画面のスクリーンショット

Twinview または Dualhead を実行している場合は、スクリーンショットを 2 回取得し、imagemagick を使用してそれらを貼り付けます:

$ import -window root -display :0.0 -screen /tmp/0.png
$ import -window root -display :0.1 -screen /tmp/1.png
$ convert +append /tmp/0.png /tmp/1.png screenshot.png
$ rm /tmp/{0,1}.png

個々の Xinerama ヘッドのスクリーンショット

Xinerama ベースのマルチヘッドセットアップには、仮想画面が 1 つだけあります。物理画面の高さが異なる場合、スクリーンショットにデッドスペースが発生します。この場合、各物理画面のスクリーンショットを個別に取得することができます。 Xinerama 情報が X サーバーから利用できる限り、以下は機能します:

#!/bin/sh
xdpyinfo -ext XINERAMA | sed '/^  head #/!d;s///' |
while IFS=' :x@,' read i w h x y; do
        import -window root -crop ${w}x$h+$x+$y head_$i.png
done

アクティブ/フォーカスされたウィンドウのスクリーンショット

次のスクリプトは、現在フォーカスされているウィンドウのスクリーンショットを取得します。EWMH/NetWM 互換の X ウィンドウマネージャーで動作します。以前のスクリーンショットが上書きされないように、現在の日付がファイル名として使用されます。

#!/bin/sh
activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
activeWinId=${activeWinLine:40}
import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png

あるいは、EWMH のサポートに関係なく、次のものが機能するはずです:

$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
ノート: 一部のプログラム (zathura など) のスクリーンショットが空白で表示される場合は、-frame を追加するか、xdotool コマンドから -f を削除してみてください。

画像データの暗号化

暗号化するには:

$ echo pass_phrase | magick image.jpg -encipher - -depth 8 png24:image.png

これは次の方法で復号化できます:

$ echo pass_phrase | magick image.png -decipher - image.jpg

このようなコマンドに関するあらゆる種類の問題や提案については、Encrypting Images のディスカッションを読むことを強くお勧めします。

cipher タグを持つ画像形式のメタデータは、暗号化のテストに使用できます。ただし、EXIF 編集プログラムによって削除または偽装される可能性があります。

$ identify -verbose image.png

一般に、ラスターイメージが暗号化されているかどうかのテストは、ピクセルコンポーネントの分布をチェックすることで実行できます。特定のしきい値を超える場合、データはランダムであると見なされ、暗号化の候補となる可能性があります。ただし、誤検知の例としては、Diamond-square algorithm で作成された画像が挙げられます。

参照