「ImageMagick」の版間の差分
(序文を更新) |
(最新の英語版に差し替え) |
||
15行目: | 15行目: | ||
See {{man|1|ImageMagick}}, or {{man|1|gm}} for GraphicsMagick. |
See {{man|1|ImageMagick}}, or {{man|1|gm}} for GraphicsMagick. |
||
+ | {{Tip|The official HTML documentation is available locally when the packages are installed: |
||
− | Popular operations include {{ic|-append}}, {{ic|-resize}}, {{ic|-rotate}}, {{ic|-quality}} and many more. For example, to combine multiple pictures into one: |
||
+ | * ImageMagick at {{ic|/usr/share/doc/ImageMagick-7/www/index.html}} |
||
+ | * GraphicsMagick at {{ic|/usr/share/doc/GraphicsMagick/www/index.html}}}} |
||
+ | === Common operations === |
||
− | $ 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''.}} |
{{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 ==== |
||
+ | |||
+ | 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 |
||
+ | |||
+ | ==== Append ==== |
||
+ | |||
+ | Combining multiple pictures into one: |
||
+ | |||
+ | $ convert -append ''input.pngs'' ''output.png'' |
||
+ | |||
+ | ==== Crop, chop ==== |
||
To crop part of multiple images and convert them to another format: |
To crop part of multiple images and convert them to another format: |
||
26行目: | 42行目: | ||
Where ''WIDTH'' and ''HEIGHT'' is the cropped output image size, and ''X'' and ''Y'' is the offset from the input image size. |
Where ''WIDTH'' and ''HEIGHT'' is the cropped output image size, and ''X'' and ''Y'' is the offset from the input image size. |
||
+ | |||
+ | 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 |
||
+ | |||
+ | ==== Limit the storage size ==== |
||
+ | |||
+ | To achieve reasonable quality for a given storage size: |
||
+ | |||
+ | $ convert image.jpg -define jpeg:extent=3000KB image_small.jpg |
||
+ | |||
+ | Hopefully, this will shorten the transmission time. Note that {{ic|-quality}}, as in |
||
+ | |||
+ | $ 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 === |
=== Screenshot taking === |
||
32行目: | 64行目: | ||
$ import -window root screenshot.jpg |
$ import -window root screenshot.jpg |
||
− | |||
− | {{ic|import}} is part of the {{Pkg|imagemagick}} package. |
||
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. |
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. |
||
41行目: | 71行目: | ||
==== Screenshot of multiple X screens ==== |
==== Screenshot of multiple X screens ==== |
||
− | If you run twinview or dualhead, simply take the screenshot twice and use {{ |
+ | If you run twinview or dualhead, simply take the screenshot twice and use {{ic|imagemagick}} to paste them together: |
{{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 |
}} |
}} |
||
77行目: | 107行目: | ||
$ 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 ( |
+ | {{Note|If screenshots of some programs (e.g. [[zathura]]) appear blank, try appending {{ic|-frame}} or removing {{ic|-f}} from the {{ic|xdotool}} command.}} |
+ | |||
+ | === Encryption of image data === |
||
+ | |||
+ | To encrypt: |
||
+ | |||
+ | $ 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'' |
||
+ | |||
+ | 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. |
||
+ | |||
+ | 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 |
||
+ | |||
+ | 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 == |
||
− | * [https://www.imagemagick.org/ ImageMagick website] for an extensive list of options and examples. |
+ | * [https://www.imagemagick.org/ ImageMagick website] for an extensive list of options, [https://imagemagick.org/Usage/ examples] and [https://imagemagick.org/script/examples.php showcase]. |
* [[List of applications/Multimedia#Image processing]] |
* [[List of applications/Multimedia#Image processing]] |
||
+ | * [http://www.fmwconcepts.com/imagemagick/index.php Fred's ImageMagick Scripts] for large collection of ImageMagic scripts |
2024年1月9日 (火) 20:17時点における版
Wikipedia から:
- ImageMagick は、ラスターイメージファイルとベクターイメージファイルを表示、変換、編集するための無料のオープンソースソフトウェアスイートです。200 を超える画像ファイル形式を読み書きできます。
Installation
Install the imagemagick package. Alternatively install graphicsmagick for GraphicsMagick, a fork of ImageMagick, emphasizing stability of the API and command-line interface.
Usage
See ImageMagick(1), or gm(1) for GraphicsMagick.
Common operations
Convert between image formats
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
Append
Combining multiple pictures into one:
$ convert -append input.pngs output.png
Crop, chop
To crop part of multiple images and convert them to another format:
$ mogrify -crop WIDTHxHEIGHT+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.
One can also -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
Limit the storage size
To achieve reasonable quality for a given storage size:
$ convert image.jpg -define jpeg:extent=3000KB image_small.jpg
Hopefully, this will shorten the transmission time. Note that -quality
, as in
$ 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
An easy way to take a screenshot of your current system is using the import(1) command:
$ import -window root screenshot.jpg
Running import
without the -window
option allows selecting a window or an arbitrary region interactively. With -pause
you can specify a delay in which you can, for example, lower some windows.
Screenshot of multiple X screens
If you run twinview or dualhead, simply take the screenshot twice and use imagemagick
to paste them together:
$ 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
Screenshot of individual Xinerama heads
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:
#!/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
Screenshot of the active/focused window
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.
#!/bin/sh activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)") activeWinId=${activeWinLine:40} import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png
Alternatively, the following should work regardless of EWMH support:
$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
Encryption of image data
To encrypt:
$ 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
It is highly advised to read the discussion at Encrypting Images for all sorts of issues, and suggestions, for such commands.
Metadata of image formats that have the 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
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 Diamond-square algorithm.
See also
- ImageMagick website for an extensive list of options, examples and showcase.
- List of applications/Multimedia#Image processing
- Fred's ImageMagick Scripts for large collection of ImageMagic scripts