「ImageMagick」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎Usage: 翻訳)
11行目: 11行目:
 
{{Pkg|imagemagick}} パッケージを [[インストール]] します。あるいは、API とコマンドラインインターフェイスの安定性を重視した ImageMagick のフォークである [[Wikipedia:GraphicsMagick|GraphicsMagick]] の {{Pkg|graphicsmagick}} をインストールします。
 
{{Pkg|imagemagick}} パッケージを [[インストール]] します。あるいは、API とコマンドラインインターフェイスの安定性を重視した ImageMagick のフォークである [[Wikipedia:GraphicsMagick|GraphicsMagick]] の {{Pkg|graphicsmagick}} をインストールします。
   
== Usage ==
+
== 使い方 ==
   
See {{man|1|ImageMagick}}, or {{man|1|gm}} for GraphicsMagick.
+
GraphicsMagick については、{{man|1|ImageMagick}} または {{man|1|gm}} を参照してください。
   
  +
{{Tip|公式 HTML ドキュメントは、パッケージをインストールするとローカルで利用できます:
{{Tip|The official HTML documentation is available locally when the packages are installed:
 
* ImageMagick at {{ic|/usr/share/doc/ImageMagick-7/www/index.html}}
+
* ImageMagick {{ic|/usr/share/doc/ImageMagick-7/www/index.html}}
* GraphicsMagick at {{ic|/usr/share/doc/GraphicsMagick/www/index.html}}}}
+
* GraphicsMagick {{ic|/usr/share/doc/GraphicsMagick/www/index.html}}}}
   
=== Common operations ===
+
=== 共通操作 ===
   
  +
{{Note|オプションの前の記号は重要です。反対の操作は、''マイナス'' の代わりに ''プラス'' を使用して実行できます。}}
{{Note|The sign before an option is important. Opposite operations can be performed by using a ''plus'' instead of a ''minus''.}}
 
   
==== Convert between image formats ====
+
==== 画像形式間の変換 ====
   
  +
この機能の基本的な使用法は、既存の希望する画像形式をファイル名拡張子として指定することです。たとえば、指定された ''.png'' 画像を ''.jpg'' にするには、次を使用します。
The basic usage of this facility is to specify the existing, and desired, image formats as the filename extension. For example, to get the ''.jpg'' representation of a given ''.png'' image, use:
 
   
 
$ convert image.png image.jpg
 
$ convert image.png image.jpg
   
==== Append ====
+
==== 追加 ====
   
  +
複数の写真を 1 つに結合する:
Combining multiple pictures into one:
 
   
 
$ convert -append ''input.pngs'' ''output.png''
 
$ convert -append ''input.pngs'' ''output.png''
   
==== Crop, chop ====
+
==== トリミング、切り取り ====
   
  +
複数の画像の一部を切り取って別の形式に変換するには:
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}} こともできます。こちらの方が、数や試行錯誤が少なくて済むので簡単です。
One can also {{ic|-chop}} to cut of a single edge from an image, using gravity to select that edge. Which is easier as less numbers, or trial and error, is involved.
 
   
 
$ magick frame_red.gif -gravity South -chop 0x10 chop_bottom.gif
 
$ magick frame_red.gif -gravity South -chop 0x10 chop_bottom.gif
   
==== Limit the storage size ====
+
==== ストレージサイズを制限する ====
   
  +
特定のストレージサイズで適切な品質を達成するには、次の手順を実行します:
To achieve reasonable quality for a given storage size:
 
   
 
$ convert image.jpg -define jpeg:extent=3000KB image_small.jpg
 
$ convert image.jpg -define jpeg:extent=3000KB image_small.jpg
   
  +
これにより変換時間が短縮されることを期待します。{{ic|-quality}} に注意してください。
Hopefully, this will shorten the transmission time. Note that {{ic|-quality}}, as in
 
   
 
$ convert image.jpg -quality 85% image_small.jpg
 
$ convert image.jpg -quality 85% image_small.jpg
   
  +
品質とストレージサイズの相関関係が明確でない場合は、使用が難しくなります。
is harder to use when the correlation between quality and storage size is not clear.
 
   
  +
=== スクリーンショットの取得 ===
=== Screenshot taking ===
 
   
  +
現在のシステムのスクリーンショットを撮る簡単な方法は、{{man|1|import}} コマンドを使用することです:
An easy way to take a screenshot of your current system is using the {{man|1|import}} command:
 
   
 
$ import -window root screenshot.jpg
 
$ import -window root screenshot.jpg
   
  +
{{ic|-window}} オプションを指定せずに {{ic|import}} を実行すると、ウィンドウまたは任意の領域を対話的に選択できます。{{ic|-pause}} を使用すると、たとえば一部のウィンドウを下げるなどの遅延を指定できます。
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.
 
   
{{Note|If you prefer '''graphicsmagick''' alternative, just prepend "gm", e.g. {{ic|$ gm import -window root screenshot.jpg}}.}}
+
{{Note|'''graphicsmagick''' の代替手段を希望する場合は、"gm" を先頭に追加します (例:{{ic|$ gm import -window rootscreenshot.jpg}})}}
   
  +
==== 複数の X 画面のスクリーンショット ====
==== Screenshot of multiple X screens ====
 
   
  +
Twinview または Dualhead を実行している場合は、スクリーンショットを 2 回取得し、{{ic|imagemagick}} を使用してそれらを貼り付けます:
If you run twinview or dualhead, simply take the screenshot twice and use {{ic|imagemagick}} to paste them together:
 
   
 
{{bc|
 
{{bc|
80行目: 80行目:
 
}}
 
}}
   
==== 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>
92行目: 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>
103行目: 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|If screenshots of some programs (e.g. [[zathura]]) appear blank, try appending {{ic|-frame}} or removing {{ic|-f}} from the {{ic|xdotool}} command.}}
+
{{Note|一部のプログラム ([[zathura]] など) のスクリーンショットが空白で表示される場合は、{{ic|-frame}} を追加するか、{{ic|xdotool}} コマンドから {{ic|-f}} を削除してみてください。}}
   
=== Encryption of image data ===
+
=== 画像データの暗号化 ===
   
  +
暗号化するには:
To encrypt:
 
   
 
$ echo ''pass_phrase'' | magick ''image.jpg'' -encipher - -depth 8 png24:''image.png''
 
$ echo ''pass_phrase'' | magick ''image.jpg'' -encipher - -depth 8 png24:''image.png''
   
  +
これは次の方法で復号化できます:
This can be decrypted by:
 
   
 
$ echo ''pass_phrase'' | magick ''image.png'' -decipher - ''image.jpg''
 
$ echo ''pass_phrase'' | magick ''image.png'' -decipher - ''image.jpg''
   
It is highly advised to read the discussion at [https://imagemagick.org/Usage/transform/#encipher Encrypting Images] for all sorts of issues, and suggestions, for such commands.
+
このようなコマンドに関するあらゆる種類の問題や提案については、[https://imagemagick.org/Usage/transform/#encipher Encrypting Images] のディスカッションを読むことを強くお勧めします。
   
  +
{{ic|cipher}} タグを持つ画像形式のメタデータは、暗号化のテストに使用できます。ただし、EXIF 編集プログラムによって削除または偽装される可能性があります。
Metadata of image formats that have the {{ic|cipher}} tag can be used to test for encryption. However, it could be removed or spoofed by an EXIF editing program.
 
   
 
$ identify -verbose image.png
 
$ identify -verbose image.png
   
  +
一般に、ラスターイメージが暗号化されているかどうかのテストは、ピクセルコンポーネントの分布をチェックすることで実行できます。特定のしきい値を超える場合、データはランダムであると見なされ、暗号化の候補となる可能性があります。ただし、誤検知の例としては、[[wikipedia:Diamond-square algorithm|Diamond-square algorithm]] で作成された画像が挙げられます。
In general, testing if a raster image was encrypted can be done by checking the distribution of the pixel components. If it exceeds a certain threshold, the data could be considered random and a possible candidate for encryption. However, an example for false positives are images created with the [[wikipedia:Diamond-square algorithm|Diamond-square algorithm]].
 
   
 
== See also ==
 
== See also ==

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

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 で作成された画像が挙げられます。

See also