Programowanie w systemie UNIX/ImageMagic
Instalacja
[edytuj]Z użyciem git ( CLI method) Metoda ręczna, wymaga kompilacji po instalacji. Zapewnia kod źródłowy i najnowszą wersję. [1] [2]
sudo apt install git -y sudo apt install make build-essential automake libltdl-dev -y # install dependencies git clone git@github.com:ImageMagick/ImageMagick.git /usr/local/src/ImageMagick cd /usr/local/src/ImageMagick sudo ./configure sudo make sudo make install sudo ldconfig /usr/local/lib
lub inny sposób użycia git
git clone https://github.com/ImageMagick/ImageMagick.git /usr/local/src/ImageMagick
Najnowsza wersja (ang. update) z użyciem git:
sudo git pull
Odinstalowanie po ręcznej instalacji
cd /usr/local/src/ImageMagick sudo make uninstall
Z użyciem apt ( CLI method), wykrywa zależności, umożliwia łatwe usunięcie. Zwykle nie zapewnia najnowszej wersji. [3]
sudo apt update && sudo apt upgrade -y sudo apt install make build-essential automake libltdl-dev -y # install dependencies sudo apt install imagemagick -y
Usinięcie z użyciem apt :
sudo apt remove imagemagick* -y
Z użyciem Ubuntu Software center (GUI method), umożliwia łatwe usunięcie
Pomoc
[edytuj]- formaty: plików, pseudoformaty
- struktura obrazu
- nazwy kolorów
- architekture
- korzystanie z linii poleceń (command-line-processing = CLI)
- narzędzia linii poleceń ( ang. command-line-tools = CLI tools)
- Color w IM z użyciem CLI (ang. color-management )
wersja
[edytuj]ver. 7
[edytuj]magick --version # from version 7
ImageMagic ver. 6
[edytuj]identify -version # for version 6 and earlier
lub:
convert --version
przykładowy wynik
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
W części Features brak HDRI, która jest dostępna od wersji 7[4]
Zamiast
convert
użyj:
magick
Linki
[edytuj]- strona domowa: http://www.imagemagick.org/
- git: http://git.imagemagick.org/repos/ImageMagick
- grupy dyskusyjne: http://www.imagemagick.org/discourse-server/
- stackoverflow: stackoverflow questions tagged imagemagick
- http://im.snibgo.com/
Opcje
[edytuj]Sprawdzamy dostepne opcje :
identify -list list
Przykładowy wynik :
Align
Alpha
Boolean
Cache
Channel
Class
ClipPath
Coder
Color
Colorspace
Command
Compliance
Complex
Compose
Compress
Configure
DataType
Debug
Decoration
Delegate
Direction
Dispose
Distort
Dither
Endian
Evaluate
FillRule
Filter
Font
Format
Function
Gradient
Gravity
Intensity
Intent
Interlace
Interpolate
Kernel
Layers
LineCap
LineJoin
List
Locale
LogEvent
Log
Magic
Method
Metric
Mime
Mode
Morphology
Module
Noise
Orientation
PixelIntensity
Policy
PolicyDomain
PolicyRights
Preview
Primitive
QuantumFormat
Resource
SparseColor
Statistic
Storage
Stretch
Style
Threshold
Type
Units
Validate
VirtualPixel
Weight
colorspace
[edytuj]Sprawdzamy dostępne opcje:
identify -list colorspace
Przykładowy wynik:
Adobe98
CIELab
CMY
CMYK
DisplayP3
Gray
HCL
HCLp
HSB
HSI
HSL
HSV
HWB
Jzazbz
Lab
LCH
LCHab
LCHuv
LinearGray
LMS
Log
Luv
OHTA
Oklab
Oklch
ProPhoto
Rec601YCbCr
Rec709YCbCr
RGB
scRGB
sRGB
Transparent
xyY
XYZ
YCbCr
YDbDr
YCC
YIQ
YPbPr
YUV
Porównaj
- snibgo's ImageMagick pages: Colorspace cookbook
- snibgo's ImageMagick pages: Greyscale gamma: RGB/sRGB
density
[edytuj]-density widthxheight
depth
[edytuj]depth = głębokość koloru ( w bitach) na kanał ( ang. channel)
Przykład
- PNG8
- PNG24 ma głębokość koloru 8 x 3 kanały ( RGB) co daje 24 bitów na kolor pixela
- PNG32 ma głębokość koloru 8 x 4 kanały ( RGBA) co daje 32 bitów na kolor pixela =
- PNG48 ma głębokość koloru 12 x 4 kanały ( RGBA) co daje 48 bitów na kolor pixela = Truecolor and alpha
- PNG64 ma głębokość koloru 16 x 4 kanały ( RGBA) co daje 64 bitów na kolor pixela = Truecolor and alpha
convert -list type
Wynik :
Bilevel ColorSeparation ColorSeparationAlpha ColorSeparationMatte Grayscale GrayscaleAlpha GrayscaleMatte Optimize Palette PaletteBilevelAlpha PaletteBilevelMatte PaletteAlpha PaletteMatte TrueColorAlpha TrueColorMatte TrueColor
Wewnętrzną reprezentacją piksela w ImageMagick: Quantum
- QuantumDepth
- Quantum Typedef
- QuantumRange:
"Internally, IM scales pixel values from the quantumrange of the 16-bit per channel images (range 0 to 65535 integers) or 8-bit per channel images (range 0 to 255 integers) to the range 0 to 1 (floats). But when processing is done, it converts back to integers of the quantumrange before writing out the image."[5]
distort
[edytuj]Sprawdzamy opcje:[6]
identify -list distort
Wynik:
Affine AffineProjection ScaleRotateTranslate SRT Perspective PerspectiveProjection BilinearForward BilinearReverse Polynomial Arc Polar DePolar Barrel BarrelInverse Shepards Resize
endianess
[edytuj]Sprawdzamy dostępne opcje :[7]
identify -list endian
Wynik :
LSB MSB
evaluate
[edytuj]Sprawdzamy listę opcji ( operatorów -evaluate-sequence )
identify -list evaluate
Przykłądowy wynik:
Abs Add AddModulus And Cos Cosine Divide Exp Exponential GaussianNoise ImpulseNoise InverseLog LaplacianNoise LeftShift Log Max Mean Median Min MultiplicativeNoise Multiply Or PoissonNoise Pow RightShift RMS RootMeanSquare Set Sin Sine Subtract Sum Threshold ThresholdBlack ThresholdWhite UniformNoise Xor
filter
[edytuj]Filtry ( ang. Filter)[8]
- resize: Point, Hermite, Cubic, Box, Gaussian, Catrom, Triangle, Quadratic, Mitchell, CubicSpline
- windowed: Lanczos, Hamming Parzen Blackman Kaiser Welsh Hanning Bartlett Bohman
Lista:
convert -list filter Bartlett Blackman Bohman Box Catrom Cosine Cubic Gaussian Hamming Hann Hermite Jinc Kaiser Lagrange Lanczos Lanczos2 Lanczos2Sharp LanczosRadius LanczosSharp Mitchell Parzen Point Quadratic Robidoux RobidouxSharp Sinc SincFast Spline Triangle Welch
Możesz modyfikować zachowanie filtra podczas skalowania obrazu, korzystając z tych ustawień specjalistycznych (zobacz -define i -set)
formaty plików
[edytuj]convert -list format
Przykładowy wynik
Format Module Mode Description
-------------------------------------------------------------------------------
3FR DNG r-- Hasselblad CFV/H3D39II
3G2 VIDEO r-- Media Container
3GP VIDEO r-- Media Container
AAI* AAI rw+ AAI Dune image
AI PDF rw- Adobe Illustrator CS2
APNG VIDEO rw+ Animated Portable Network Graphics
ART* ART rw- PFS: 1st Publisher Clip Art
ARW DNG r-- Sony Alpha Raw Image Format
AVI VIDEO r-- Microsoft Audio/Visual Interleaved
AVIF* HEIC rw+ AV1 Image File Format (1.11.0)
AVS* AVS rw+ AVS X image
BGR* BGR rw+ Raw blue, green, and red samples
BGRA* BGR rw+ Raw blue, green, red, and alpha samples
BGRO* BGR rw+ Raw blue, green, red, and opacity samples
BIE* JBIG rw- Joint Bi-level Image experts Group interchange format (2.1)
BMP* BMP rw- Microsoft Windows bitmap image
BMP2* BMP rw- Microsoft Windows bitmap image (V2)
BMP3* BMP rw- Microsoft Windows bitmap image (V3)
BRF* BRAILLE -w- BRF ASCII Braille format
CAL* CALS rw- Continuous Acquisition and Life-cycle Support Type 1
Specified in MIL-R-28002 and MIL-PRF-28002
CALS* CALS rw- Continuous Acquisition and Life-cycle Support Type 1
Specified in MIL-R-28002 and MIL-PRF-28002
CANVAS* XC r-- Constant image uniform color
CAPTION* CAPTION r-- Caption
CIN* CIN rw- Cineon Image File
CIP* CIP -w- Cisco IP phone image format
CLIP* CLIP rw+ Image Clip Mask
CMYK* CMYK rw+ Raw cyan, magenta, yellow, and black samples
CMYKA* CMYK rw+ Raw cyan, magenta, yellow, black, and alpha samples
CR2 DNG r-- Canon Digital Camera Raw Image Format
CR3 DNG r-- Canon Digital Camera Raw Image Format
CRW DNG r-- Canon Digital Camera Raw Image Format
CUR* ICON rw- Microsoft icon
CUT* CUT r-- DR Halo
DATA* INLINE rw+ Base64-encoded inline images
DCM* DCM r-- Digital Imaging and Communications in Medicine image
DICOM is used by the medical community for images like X-rays. The
specification, "Digital Imaging and Communications in Medicine
(DICOM)", is available at http://medical.nema.org/. In particular,
see part 5 which describes the image encoding (RLE, JPEG, JPEG-LS),
and supplement 61 which adds JPEG-2000 encoding.
DCR DNG r-- Kodak Digital Camera Raw Image File
DCX* PCX rw+ ZSoft IBM PC multi-page Paintbrush
DDS* DDS rw+ Microsoft DirectDraw Surface
DFONT* TTF r-- Multi-face font package (Freetype 2.10.4)
DJVU* DJVU r-- Deja vu
See http://www.djvuzone.org/ for details about the DJVU format. The
DJVU 1.2 specification is available there and at
ftp://swrinde.nde.swri.edu/pub/djvu/documents/.
DNG DNG r-- Digital Negative
DOT DOT --- Graphviz
DPX* DPX rw- SMPTE 268M-2003 (DPX 2.0)
Digital Moving Picture Exchange Bitmap, Version 2.0.
See SMPTE 268M-2003 specification at http://www.smtpe.org
DXT1* DDS rw+ Microsoft DirectDraw Surface
DXT5* DDS rw+ Microsoft DirectDraw Surface
EPDF PDF rw- Encapsulated Portable Document Format
EPI PS rw- Encapsulated PostScript Interchange format
EPS PS rw- Encapsulated PostScript
EPS2 PS2 -w- Level II Encapsulated PostScript
EPS3 PS3 -w+ Level III Encapsulated PostScript
EPSF PS rw- Encapsulated PostScript
EPSI PS rw- Encapsulated PostScript Interchange format
EPT EPT rw- Encapsulated PostScript with TIFF preview
EPT2 EPT rw- Encapsulated PostScript Level II with TIFF preview
EPT3 EPT rw+ Encapsulated PostScript Level III with TIFF preview
ERF DNG r-- Epson Raw Format
EXR EXR rw- High Dynamic-range (HDR) (OpenEXR 2.5.4)
FAX* FAX rw+ Group 3 FAX
FAX machines use non-square pixels which are 1.5 times wider than
they are tall but computer displays use square pixels, therefore
FAX images may appear to be narrow unless they are explicitly
resized using a geometry of "150x100%".
FILE* URL r-- Uniform Resource Locator (file://)
FITS* FITS rw- Flexible Image Transport System
FRACTAL* PLASMA r-- Plasma fractal image
FTP* URL r-- Uniform Resource Locator (ftp://)
FTS* FITS rw- Flexible Image Transport System
G3* FAX rw- Group 3 FAX
G4* FAX rw- Group 4 FAX
GIF* GIF rw+ CompuServe graphics interchange format
GIF87* GIF rw- CompuServe graphics interchange format (version 87a)
GRADIENT* GRADIENT r-- Gradual linear passing from one shade to another
GRAY* GRAY rw+ Raw gray samples
GRAYA* GRAY rw+ Raw gray and alpha samples
GROUP4* TIFF rw- Raw CCITT Group4
GV DOT --- Graphviz
H* MAGICK -w- Image expressed as a 'C/C++' char array
HALD* HALD r-- Identity Hald color lookup table image
HDR* HDR rw+ Radiance RGBE image format
HEIC* HEIC rw+ Apple High efficiency Image Format (1.11.0)
HISTOGRAM* HISTOGRAM -w- Histogram of the image
HRZ* HRZ rw- Slow Scan TeleVision
HTM* HTML -w- Hypertext Markup Language and a client-side image map
HTML* HTML -w- Hypertext Markup Language and a client-side image map
HTTP* URL r-- Uniform Resource Locator (http://)
HTTPS* URL r-- Uniform Resource Locator (https://)
ICB* TGA rw- Truevision Targa image
ICO* ICON rw+ Microsoft icon
ICON* ICON rw- Microsoft icon
IIQ DNG r-- Phase One Raw Image Format
INFO INFO -w+ The image format and characteristics
INLINE* INLINE rw+ Base64-encoded inline images
IPL* IPL rw+ IPL Image Sequence
ISOBRL* BRAILLE -w- ISO/TR 11548-1 format
ISOBRL6* BRAILLE -w- ISO/TR 11548-1 format 6dot
J2C* JP2 rw- JPEG-2000 Code Stream Syntax (2.3.1)
J2K* JP2 rw- JPEG-2000 Code Stream Syntax (2.3.1)
JBG* JBIG rw+ Joint Bi-level Image experts Group interchange format (2.1)
JBIG* JBIG rw+ Joint Bi-level Image experts Group interchange format (2.1)
JNG* PNG rw- JPEG Network Graphics
See http://www.libpng.org/pub/mng/ for details about the JNG
format.
JNX* JNX r-- Garmin tile format
JP2* JP2 rw- JPEG-2000 File Format Syntax (2.3.1)
JPC* JP2 rw- JPEG-2000 Code Stream Syntax (2.3.1)
JPE* JPEG rw- Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.6)
JPEG* JPEG rw- Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.6)
JPG* JPEG rw- Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.6)
JPM* JP2 rw- JPEG-2000 Code Stream Syntax (2.3.1)
JPS* JPEG rw- Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.6)
JPT* JP2 rw- JPEG-2000 File Format Syntax (2.3.1)
JSON JSON -w+ The image format and characteristics
K25 DNG r-- Kodak Digital Camera Raw Image Format
KDC DNG r-- Kodak Digital Camera Raw Image Format
LABEL* LABEL r-- Image label
M2V VIDEO rw+ MPEG Video Stream
M4V VIDEO rw+ Raw VIDEO-4 Video
MAC* MAC r-- MAC Paint
MAGICK* MAGICK rw- Predefined Magick Image (LOGO, ROSE, etc.); output same as 'H'
MAP* MAP rw- Colormap intensities and indices
MASK* MASK rw+ Image Clip Mask
MAT MAT rw+ MATLAB level 5 image format
MATTE* MATTE -w+ MATTE format
MEF DNG r-- Mamiya Raw Image File
MIFF* MIFF rw+ Magick Image File Format
MKV VIDEO rw+ Multimedia Container
MNG* PNG rw+ Multiple-image Network Graphics (libpng 1.6.37)
See http://www.libpng.org/pub/mng/ for details about the MNG
format.
MONO* MONO rw- Raw bi-level bitmap
MOV VIDEO rw+ MPEG Video Stream
MP4 VIDEO rw+ VIDEO-4 Video Stream
MPC* MPC rw+ Magick Persistent Cache image format
MPG VIDEO rw+ MPEG Video Stream
MRW DNG r-- Sony (Minolta) Raw Image File
MSL* MSL rw+ Magick Scripting Language
MSVG* SVG rw+ ImageMagick's own SVG internal renderer
MTV* MTV rw+ MTV Raytracing image format
MVG* MVG rw- Magick Vector Graphics
NEF DNG r-- Nikon Digital SLR Camera Raw Image File
NRW DNG r-- Nikon Digital SLR Camera Raw Image File
NULL* NULL rw- Constant image of uniform color
ORF DNG r-- Olympus Digital Camera Raw Image File
OTB* OTB rw- On-the-air bitmap
OTF* TTF r-- Open Type font (Freetype 2.10.4)
PAL* UYVY rw- 16bit/pixel interleaved YUV
PALM* PALM rw+ Palm pixmap
PAM* PNM rw+ Common 2-dimensional bitmap format
PANGO* PANGO r-- Pango Markup Language (Pangocairo 1.48.2)
PATTERN* PATTERN r-- Predefined pattern
PBM* PNM rw+ Portable bitmap format (black and white)
PCD* PCD rw- Photo CD
PCDS* PCD rw- Photo CD
PCL PCL rw+ Printer Control Language
PCT* PICT rw- Apple Macintosh QuickDraw/PICT
PCX* PCX rw- ZSoft IBM PC Paintbrush
PDB* PDB rw+ Palm Database ImageViewer Format
PDF PDF rw+ Portable Document Format
PDFA PDF rw+ Portable Document Archive Format
PEF DNG r-- Pentax Electronic File
PES* PES r-- Embrid Embroidery Format
PFA* TTF r-- Postscript Type 1 font (ASCII) (Freetype 2.10.4)
PFB* TTF r-- Postscript Type 1 font (binary) (Freetype 2.10.4)
PFM* PFM rw+ Portable float format
PGM* PNM rw+ Portable graymap format (gray scale)
PGX* PGX rw- JPEG 2000 uncompressed format
PICON* XPM rw- Personal Icon
PICT* PICT rw- Apple Macintosh QuickDraw/PICT
PIX* PIX r-- Alias/Wavefront RLE image format
PJPEG* JPEG rw- Joint Photographic Experts Group JFIF format (libjpeg-turbo 2.0.6)
PLASMA* PLASMA r-- Plasma fractal image
PNG* PNG rw- Portable Network Graphics (libpng 1.6.37)
See http://www.libpng.org/ for details about the PNG format.
PNG00* PNG rw- PNG inheriting bit-depth, color-type from original if possible
PNG24* PNG rw- opaque or binary transparent 24-bit RGB (zlib 1.2.11)
PNG32* PNG rw- opaque or transparent 32-bit RGBA
PNG48* PNG rw- opaque or binary transparent 48-bit RGB
PNG64* PNG rw- opaque or transparent 64-bit RGBA
PNG8* PNG rw- 8-bit indexed with optional binary transparency
PNM* PNM rw+ Portable anymap
POCKETMOD PDF rw+ Pocketmod Personal Organizer
PPM* PNM rw+ Portable pixmap format (color)
PREVIEW* PREVIEW -w- Show a preview an image enhancement, effect, or f/x
PS PS rw+ PostScript
PS2 PS2 -w+ Level II PostScript
PS3 PS3 -w+ Level III PostScript
PSB* PSD rw+ Adobe Large Document Format
PSD* PSD rw+ Adobe Photoshop bitmap
PTIF* TIFF rw+ Pyramid encoded TIFF
PWP* PWP r-- Seattle Film Works
RADIAL-GRADIENT* GRADIENT r-- Gradual radial passing from one shade to another
RAF DNG r-- Fuji CCD-RAW Graphic File
RAS* SUN rw+ SUN Rasterfile
RAW DNG r-- Raw
RGB* RGB rw+ Raw red, green, and blue samples
RGBA* RGB rw+ Raw red, green, blue, and alpha samples
RGBO* RGB rw+ Raw red, green, blue, and opacity samples
RGF* RGF rw- LEGO Mindstorms EV3 Robot Graphic Format (black and white)
RLA* RLA r-- Alias/Wavefront image
RLE* RLE r-- Utah Run length encoded image
RMF DNG r-- Raw Media Format
RW2 DNG r-- Panasonic Lumix Raw Image
SCR* SCR r-- ZX-Spectrum SCREEN$
SCT* SCT r-- Scitex HandShake
SFW* SFW r-- Seattle Film Works
SGI* SGI rw+ Irix RGB image
SHTML* HTML -w- Hypertext Markup Language and a client-side image map
SIX* SIXEL rw- DEC SIXEL Graphics Format
SIXEL* SIXEL rw- DEC SIXEL Graphics Format
SPARSE-COLOR* TXT -w+ Sparse Color
SR2 DNG r-- Sony Raw Format 2
SRF DNG r-- Sony Raw Format
STEGANO* STEGANO r-- Steganographic image
SUN* SUN rw+ SUN Rasterfile
SVG* SVG rw+ Scalable Vector Graphics (XML 2.9.10)
SVGZ* SVG rw+ Compressed Scalable Vector Graphics (XML 2.9.10)
TEXT* TXT rw+ Text
TGA* TGA rw- Truevision Targa image
THUMBNAIL* THUMBNAIL -w+ EXIF Profile Thumbnail
TIFF* TIFF rw+ Tagged Image File Format (LIBTIFF, Version 4.3.0)
TIFF64* TIFF rw+ Tagged Image File Format (64-bit) (LIBTIFF, Version 4.3.0)
TILE* TILE r-- Tile image with a texture
TIM* TIM r-- PSX TIM
TTC* TTF r-- TrueType font collection (Freetype 2.10.4)
TTF* TTF r-- TrueType font (Freetype 2.10.4)
TXT* TXT rw+ Text
UBRL* BRAILLE -w- Unicode Text format
UBRL6* BRAILLE -w- Unicode Text format 6dot
UIL* UIL -w- X-Motif UIL table
UYVY* UYVY rw- 16bit/pixel interleaved YUV
VDA* TGA rw- Truevision Targa image
VICAR* VICAR rw- VICAR rasterfile format
VID* VID rw+ Visual Image Directory
VIDEO VIDEO rw+ MPEG Video Stream
VIFF* VIFF rw+ Khoros Visualization image
VIPS* VIPS rw+ VIPS image
VST* TGA rw- Truevision Targa image
WBMP* WBMP rw- Wireless Bitmap (level 0) image
WEBM VIDEO rw+ Open Web Media
WEBP* WEBP rw+ WebP Image Format (libwebp 0.6.1 [020E])
WMF* WMF r-- Windows Meta File
WMV VIDEO rw+ Windows Media Video
WMZ* WMF r-- Compressed Windows Meta File
WPG* WPG r-- Word Perfect Graphics
X* X rw+ X Image
X3F DNG r-- Sigma Camera RAW Picture File
XBM* XBM rw- X Windows system bitmap (black and white)
XC* XC r-- Constant image uniform color
XCF* XCF r-- GIMP image
XPM* XPM rw- X Windows system pixmap (color)
XPS XPS r-- Microsoft XML Paper Specification
XV* VIFF rw+ Khoros Visualization image
XWD* XWD rw- X Windows system window dump (color)
YCbCr* YCbCr rw+ Raw Y, Cb, and Cr samples
YCbCrA* YCbCr rw+ Raw Y, Cb, Cr, and alpha samples
YUV* YUV rw- CCIR 601 4:1:1 or 4:2:2
* native blob support
r read support
w write support
+ support for multiple images
limity
[edytuj]Limity:[9] Sprawdzamy
identify -list resource
lub
convert -list resource
Przykładowy wynik:
Resource limits: Width: 107.374MP Height: 107.374MP Area: 33.1866GP List length: unlimited Memory: 15.4537GiB Map: 30.9074GiB Disk: unlimited File: 768 Thread: 8 Throttle: 0 Time: unlimited
Możemy zmieniać :[10]
convert -limit memory 32 -limit map 64
policy.xml
[edytuj]- xml
- read-only
- zawierający ustawienia
Najpierw znajdujemy plik :
sudo find /etc -name "policy.xml"
wynik:
/etc/ImageMagick-6/policy.xml
Znajdujemy odpowiednie parametry, np width i height:
<policy domain="resource" name="width" value="16KP"/>
<policy domain="resource" name="height" value="16KP"/>
Zmieniamy w edytorze:
sudo gedit /etc/ImageMagick-6/policy.xml
Użycie
[edytuj]Metody
- z konsoli
- poprzez języki programowania
c
[edytuj]- The MagickWand API is the recommended interface between the C programming language and the ImageMagick image processing libraries.
- The MagickCore API is a low-level interface between the C programming language and the ImageMagick image processing libraries and is recommended for wizard-level programmers only.
Instalacja :
apt-get install libmagickwand-dev
Przykłady użycia
[edytuj]
Polecenia dla wersji 7
- magick (for convert)
- magick identify (for identify)
- magick mogrify (for mogrify)
- magick montage (for montage)
Informacje o pliku
[edytuj]Narzędzia linii poleceń (CLI)
- identify uzywa PingImage. PingImage() odczytuje cały obraz, ale odrzuca piksele, dzięki czemu jest szybki i wydajny pod względem pamięci.
identify -verbose rose.jpg
Głębokość i wymiary pliku raw należy określić w wierszu poleceń:
identify -depth 8 -size 640x480 image.raw
Przykładowy wynik
image.raw RGB 640x480 sRGB 9kb 0.000u 0:01
profil ICC
[edytuj]Wydobycie wbudowanego profilu ICC z pliku graficznego :[15]
convert photo.jpg profile.icc
Plik : tworzenie
[edytuj]Tworzenie pliku[16]
- żródło
- methoda
- programy linii poleceń (CLI)
- r ecznie wprowadzane polecenie lub polecenia
- skrypt Bash
- kompilowany programy w C ( constitute.c )
- programy linii poleceń (CLI)
- typ pliku
- wektorowe[20]
Skrypt bash tworzący pliki różnych typów:[21]
#!/bin/bash
files=(test.gif test.jpg test.bmp PNG8:testPNG8.png PNG24:testPNG24.png PNG32:testPNG32.png PNG48:testPNG48.png PNG64:testPNG64.png test.tif)
for f in "${files[@]}"; do
magick xc:red xc:lime +append \( xc:blue xc:magenta +append \) -append -resize 600x600 "$f"
done
Zobacz również
- profil: wbudowane profile obrazu ( ang. Embedded Image Profiles )[22]
pfm
[edytuj]Tworzymy plik[23]
- pfm ( PF = RGB color image)
- wielkość 100x100 co daje 120.0 kB
- endianess
- wypełniony jednolitym czerwonym kolorem ( Pseudo-image Format xc )
convert -size 100x100 xc:red -endian LSB red_LSB.pfm convert -size 100x100 xc:red -endian MSB red_MSB.pfm
Sprawdzmy:
xxd red_LSB.pfm|head
00000000: 5046 0a31 3030 2031 3030 0a2d 312e 300a PF.100 100.-1.0.
00000010: 0000 803f 0000 0000 0000 0000 0000 803f ...?...........?
00000020: 0000 0000 0000 0000 0000 803f 0000 0000 ...........?....
00000030: 0000 0000 0000 803f 0000 0000 0000 0000 .......?........
00000040: 0000 803f 0000 0000 0000 0000 0000 803f ...?...........?
00000050: 0000 0000 0000 0000 0000 803f 0000 0000 ...........?....
00000060: 0000 0000 0000 803f 0000 0000 0000 0000 .......?........
00000070: 0000 803f 0000 0000 0000 0000 0000 803f ...?...........?
00000080: 0000 0000 0000 0000 0000 803f 0000 0000 ...........?....
00000090: 0000 0000 0000 803f 0000 0000 0000 0000 .......?........
xxd red_MSB.pfm|head
00000000: 5046 0a31 3030 2031 3030 0a31 2e30 0a3f PF.100 100.1.0.?
00000010: 8000 0000 0000 0000 0000 003f 8000 0000 ...........?....
00000020: 0000 0000 0000 003f 8000 0000 0000 0000 .......?........
00000030: 0000 003f 8000 0000 0000 0000 0000 003f ...?...........?
00000040: 8000 0000 0000 0000 0000 003f 8000 0000 ...........?....
00000050: 0000 0000 0000 003f 8000 0000 0000 0000 .......?........
00000060: 0000 003f 8000 0000 0000 0000 0000 003f ...?...........?
00000070: 8000 0000 0000 0000 0000 003f 8000 0000 ...........?....
00000080: 0000 0000 0000 003f 8000 0000 0000 0000 .......?........
00000090: 0000 003f 8000 0000 0000 0000 0000 003f ...?...........?
Tworzymy plik pfm w skali szarości ( Pf) :
convert -size 100x100 xc:Gray -colorspace Gray gray.pfm
sprawdzamy:
xxd gray.pfm|head
Wynik :
00000000: 5066 0a31 3030 2031 3030 0a2d 312e 300a Pf.100 100.-1.0.
00000010: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000020: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000030: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000040: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000050: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000060: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000070: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000080: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
00000090: fdfc fc3e fdfc fc3e fdfc fc3e fdfc fc3e ...>...>...>...>
Wielkośc pliku:
wc -c red_MSB.pfm
lub
ls -l *
Wyniki:
- red_LSB.pfm = 120016 B = 120.0 kB
- red_MSB.pfm = 120015 B = 120.0 kB ( o jeden mniej bajt niż LSB, znak minus)
- gray.pfm = 40016 B = 40.0 kB ( czyli 3 razy mniejszy od pliku RGB, pomijając nagłówek red_LSB.pfm czyli 16 B )
png
[edytuj]magick rose: PNG32:rose32.png magick rose: PNG64:rose64.png convert rose: -colors 64 rose64.png convert input.tif PNG64:output.png # Force 64-bit RGBA (3 channels @ 16-bits each, plus alpha) convert input.tif PNG32:output.png # Force 32-bit RGBA (3 channels @ 8-bits each, plus alpha) convert input.tif PNG48:output.png # Force 48-bit output (3 channels @ 16-bits each, no alpha) convert input.tif PNG24:output.png # Force 24-bit output (3 channels @ 8-bits each, no alpha) convert input.tif PNG64:output.png # PNG64 has a color depth of 16 x 4 channels ( RGBA) which is 64 bits per pixel color = Truecolor and alpha convert input.tif -depth 16 -type TrueColorAlpha output.png convert input.png -type palette output.png # Force palettised (indexed) output convert input.png -type truecolor output.png # Force true colour output convert input.png -depth 8 output.png # Force 8-bit output convert input.png -depth 16 output.png # Force 16-bit (per channel) output convert input.tif -type TrueColorAlpha output.png # Force a true color output with transparency convert -size 640x$(($(stat -c %s /bin/bash)/640)) -depth 8 gray:/bin/bash /tmp/bash.png # https://stackoverflow.com/questions/6314214/what-is-binary-data
Formaty pliku wynikowego
- PNG Sub-Formats
- PNG: Default. Save image using economical format.
- PNG8: The PNG equivalent to GIF, including Boolean transparency and a 256 color table.
- PNG24: 8 bit RGB channels without an alpha channel. Special case can include boolean transparency (see below)
- PNG32: Force a full RGBA image format with full semi-transparency.
- PNG48: 16 bit RGB channels without alpha channel
- PNG64: 16 bit RGBA image (including semi-transparency)
- PNG00: Inherit PNG color and bit depth from input image.
pliki wbudowane w IM
[edytuj]Wbudowane pliki ( wielkość):
- GRANITE (128x128)
- LOGO (640x480)
- NETSCAPE (216x144)
- ROSE (70x46)
Tworzenie pliku z obrazem rózy na podstawie wbudowanego pliku rose ( stała wielkość
convert rose: rose.png
Powiększenie
convert ROSE: -resize 1000x1000 rose.png
pattern
[edytuj]Wbudowane wzory ( ang. pattern):
convert -size 1000x1000 pattern:checkerboard a.png
convert pattern:checkerboard -scale 120x120 -normalize -virtual-pixel tile -distort Perspective '0,0 10,61 119,0 60,60 0,119 5,114 119,119 125,110' checkered_plain.png
Plik checks ( special checkerboard with a gold outline)
convert -size 90x90 pattern:checkerboard -normalize -fill none \
-stroke gold -strokewidth 3 -draw 'rectangle 0,0 89,89' \
-fill red -draw 'color 20,20 floodfill' \
-fill lime -draw 'color 40,70 floodfill' \
-fill dodgerblue -draw 'color 70,40 floodfill' \
checks.png
Operator „-implode” wypacza obraz w taki sposób, aby przyciągnąć wszystkie piksele do środka.
convert -size 94x94 xc:red -bordercolor white -border 3 \
-virtual-pixel tile -resize 400% -implode 4 -resize 25% \
implode_tiled_ss.png
Wybuchające obrazy Używając wartości ujemnej z operatorem „-implode”, możesz rozbić obraz. Przypomina to jednak bardziej powiększanie środka obrazu i wypychanie wszystkich pikseli średniego promienia w stronę krawędzi, a nie prawdziwą eksplozję.
convert koala.gif -implode -2 explode.jpg
Przykłady zniekształcenia łuku
Za pomocą zniekształcenia łuku można wygenerować ciekawe efekty, na przykład wykreślenie długiego wzoru szachownicy w pierścieniu (przy użyciu ustawienia wirtualnego piksela „HorizontalTile” tworzy...
convert -size 210x30 pattern:checkerboard -alpha set -virtual-pixel HorizontalTile -background SkyBlue -distort Arc 360 arc_checks.png
test
[edytuj]#!/bin/bash
#
# Generate a test image for IM examples.
#
# The Image contains fully-transparent, half-transparent and fully-opaque
# reagions of the a full greyscale (black to white). It also contains regions
# of pure black, white, and other colors, so as to give IM a good workout when
# used in testing canvas and color modifications.
#
# This could actually be done all in one operation, but for debugging I like
# to be able to see the intermediate images.
#
####
#
# Anthony Thyssen Feburary 2004 <A.Thyssen@griffith.edu.au>
# Draw fancy horizontal gradient...
# magick -size 100x25 xc:white -size 100x100 gradient: -size 100x25 xc:black \
# -append -rotate 90 -blur 0x5 +repage test_gradient.png
magick -size 100x150 gradient: -rotate 90 \
-sigmoidal-contrast 7x50% test_gradient.png
# Create a semi-transparent rectangle of the gradient and flop it left-right
magick -size 150x100 xc:black \
-draw 'fill grey50 rectangle 8,8 142,92' +matte \
test_gradient.png +swap -compose CopyOpacity -composite \
-flop ${png_format}test_bgnd.png
# Draw two overlaping circles and fill then with same (non-flopped) gradient.
magick -size 150x100 xc:black \
-draw 'fill white circle 40,50 40,12' \
-draw 'fill white circle 110,50 110,12' +matte \
test_gradient.png +swap -compose CopyOpacity -composite \
test_fgnd.png
# Create a rainbow gradient
magick -size 12x100 xc:Lime -colorspace HSB \
gradient:gray66 -compose CopyRed -composite \
-colorspace sRGB -rotate 90 -compose Over \
-bordercolor black -border 0x1 test_hue.png
# Overlay the images and add some extra colors to result.
# -draw 'fill green rectangle 40,64 110,96' \
magick test_bgnd.png test_fgnd.png -composite \
-draw 'fill red circle 25,80 25,98' \
-draw 'fill green circle 75,80 75,98' \
-draw 'fill blue circle 125,80 125,98' \
test_hue.png -geometry +25+80 -composite \
test.png
# Remove the intermediate images (comment if debugging)
rm -f test_gradient.png test_bgnd.png test_fgnd.png test_hue.png
# Overlay on the pages background color to generate a JPEG
# For stupid IE web clients that do not understand PNG transparency
#magick test.png \
# \( +clone -fill "$page_bg_color" -draw 'color 0,0 reset' \) \
# -compose Dst_Over -composite $jpg_opt test.jpg
# set permissions
chmod 644 test.png
Plik: sprawdzanie
[edytuj]identify -verbose red_MSB.pfm
Przykładowy wynik:
Image: red_MSB.pfm
Format: PFM (Portable float format)
Class: DirectClass
Geometry: 100x100+0+0
Units: Undefined
Type: Palette
Base type: TrueColor
Endianess: MSB
Colorspace: sRGB
Depth: 32/1-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
Channel statistics:
Pixels: 10000
Red:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -nan
Green:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -nan
Blue:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -nan
Image statistics:
Overall:
min: 0 (0)
max: 65535 (1)
mean: 21845 (0.333333)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: -nan
Colors: 1
Histogram:
10000: (4294967295, 0, 0) #FFFFFFFF0000000000000000 red
Rendering intent: Perceptual
Gamma: 0.454545
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Background color: white
Border color: srgb(223,223,223)
Matte color: grey74
Transparent color: black
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 100x100+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2019-12-01T09:28:02+01:00
date:modify: 2019-12-01T09:28:02+01:00
signature: f3c3843113c9eab20f5826f19024dcbc4e4f5532b94d47bb5d5b80ed30d380f6
Artifacts:
filename: red_MSB.pfm
verbose: true
Tainted: False
Filesize: 120KB
Number pixels: 10K
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Plik: wyświetlanie
[edytuj]display red_LSB.pfm
Plik: konwersja
[edytuj]Kolor
convert a.png -depth 12 PNG48:b.png
Mieszanie kolorów musi odbywać się w świetle liniowym, a nie sRGB. Na przykład skalowanie w dół za pomocą kodu ImageMagic
convert large.png -colorspace RGB -geometry 640x360 -colorspace sRGB small.png
Zmień rozmiar obrazów do określonej wartości wysokości[26]
convert input.png -geometry x600 output.png
zmiana wielkości ( width=600 przy zachowanym aspect ratio) wielu plików
mogrify -geometry x600 *.png
Zmiana wielkośći i typu ( z pgm na png)
mogrify -geometry x600 -format png *.pgm
gradient koloru
[edytuj]Przykłady:[30]
gradient dyskretny:
convert input.pgm -level 0,65532 clut.ppm -interpolate integer -clut -depth 8 output.png
gradient ciągły
convert input.pgm -level 0,65532 clut.ppm -clut -depth 8 output.png
paleta
[edytuj]Paleta z obrazu ( w trybie indeksowanym)[31]
convert m.png -unique-colors -colors 256 -format %c -depth 8 histogram:info:->palette2.txt
gamma
[edytuj]składnia:[32]
-gamma value
przykład uzycia
convert input.png -gamma .45455 output.png
Wartości:
- zwykle pomiędzy 0.8 do 2.3
- mniejsze niż 1.0 ściemniają
- większe niż 1.0 rozjaśniają
Zobacz również:
Szum
[edytuj]Lista dostępnych typów szumu ( ang. noise)
convert -list noise
Typu
- Gaussian
- Impulse
- Laplacian
- Multiplicative
- Poisson
- Random
- Uniform = no noise = solid gray
Utworzymy plik :
convert -size 1000x1000 xc:Gray -colorspace Gray +noise Uniform uniform.pgm
Opecje:
convert -size 300x200 xc:gray -attenuate 0.5 +noise random out.bmp
convert -size 600x400 xc:gray +noise random -colorspace gray -threshold 50% noise.png
histogram
[edytuj]Histogram w postaci:[37]
- pliku z wykresem
- pliku tekstowego
convert gauss.pgm -colorspace Gray -define histogram:unique-colors=false histogram:g.png
porównanie plików ( diff)
[edytuj]Image magic ma funkcję compare
compare a.png b.png delta.png
evaluate-sequence
[edytuj]Opcja wiersza poleceń[38]
-evaluate-sequence operator
Pozwala na zmianę pikseli w kanałach kolorów poprzez ocenę w w sekwencji obrazów:
- wyrażenie arytmetyczne
- wyrażenia relacyjnego
- wyrażenia logicznego
Każdy kanał koloru jest przetwarzany niezależnie od siebie.
Upewnij się, że wszystkie obrazy w sekwencji są w tej samej przestrzeni kolorów, w przeciwnym razie możesz uzyskać nieoczekiwane rezultaty, np. dodaj -colorspace sRGB do swojego wiersza poleceń.
A jeśli korzystasz z losowe próbkowanie, to mediana kilku obrazów z różnymi ustawieniami próbkowania może być wykorzystana do uzyskania gładszego końcowego obrazu:[39]
convert <SomeDirectory>\*.png -evaluate-sequence median MEDIAN.png
depolar distortion
[edytuj]Konwersja koła do linii ( rozwijanie koła ang. unrolling circle):[40]
convert sun.jpg +distort DePolar 0 result.jpg
Przekształcenie
- polar distortion ( linia w koło )[41]
- depolar distortion ( koło w linie, odwrotne)
convert checks.png -virtual-pixel HorizontalTile -background Black -distort Polar 0 checks_polar.png
convert checks_polar.png -distort DePolar 0 checks_polar_depolar.png
Triki[42]
Problemy
[edytuj]convert-im6.q16hdri: cache resources exhausted
[edytuj]Przy konwersji duzego pliku pojawia się komunikat:
convert-im6.q16hdri: cache resources exhausted
Rozwiązanie: zmiana limitów:
- dysk[43]
Sprawdzamy limity:[44]
identify -list policy
Zmieniamy doraźnie:[45]
convert -limit memory 100mb -limit disk 1gb -resize 100x100 p.png p2.png
Zmieniamy limity na stałe w pliku policy.xml:
sudo gedit /etc/ImageMagick-6/policy.xml
z :
<policy domain="resource" name="disk" value="1GiB">
na
<policy domain="resource" name="disk" value="10GiB"/>
pomoc
[edytuj]Online
[edytuj]offline
[edytuj]convert --help
lub
man convert
Porównaj
[edytuj]Źródła
[edytuj]- ↑ How to Install ImageMagick on Ubuntu 22.04 LTS Published on: April 29, 2022 by Joshua James
- ↑ linuxopsys : install-latest-imagemagick-on-ubuntu
- ↑ Install ImageMagick on Ubuntu By Sagar Sharma Updated on September 13, 2022
- ↑ imagemagick high-dynamic-range
- ↑ imagemagick.org: dyskusja
- ↑ imagemagick command-line-options: distort
- ↑ imagemagick : endian
- ↑ imagemagick command-line-options filter
- ↑ imagemagick command-line-options : limit
- ↑ Image Magick : limit
- ↑ askubuntu question: imagemagick-command-line-convert-limit-values
- ↑ imagemagick resources
- ↑ commons:Category:Created_with_ImageMagick
- ↑ commons:Category:Images_with_Image_Magic_source_code
- ↑ rawpedia: how to extract and examine ICC profiles ?
- ↑ imagemagick : canvas creation
- ↑ Wbudowane obrazy
- ↑ wbudowane wzory
- ↑ pseudo formats
- ↑ imagemagick : magick-vector-graphics
- ↑ stackoverflow question: different-image-file-format-samples
- ↑ Embedded Image Profiles
- ↑ stackoverflow question : does-anyone-know-how-to-convert-to-little-endian-pfm-file-from-imagemagic
- ↑ png write
- ↑ stackoverflow question: imagemagick-convert-tif-to-rgba16-png
- ↑ askubuntu question: resize-images-to-specific-height-value-in-imagemagick
- ↑ imagemagick Usage color mods (CLUT)
- ↑ Greyscale gamma: RGB/sRGB by Alan Gibson.
- ↑ imagemagick Usage: color basics
- ↑ Paul Tol's Notes
- ↑ imagemagick : identify
- ↑ image magick : gamma
- ↑ autogamma -Fred's ImageMagick Scripts
- ↑ h vidtfeldts : gamma-correction
- ↑ stackoverflow question: generate-random-bmp-in-cli
- ↑ stackoverflow question: generate-image-of-certain-resolution-containing-black-and-white-noise
- ↑ imagemagick : histogram
- ↑ imagemagick : command-line-options
- ↑ imagemagick-average-blending-files by Pat David
- ↑ stackoverflow question: converting-an-image-from-cartesian-to-polar-limb-darkening
- ↑ image magick distorts: polar and depolar
- ↑ imagemagick Usage distorts polar_tricks
- ↑ ImageMagick cache resources exhausted resolved by Grant
- ↑ imagemagick: architecture, tera-pixel
- ↑ imagemagick: Cache resources exhausted