{"id":17842077,"url":"https://github.com/yangboz/imagemagick-cheatsheet","last_synced_at":"2025-04-02T14:12:03.411Z","repository":{"id":139103391,"uuid":"138963542","full_name":"yangboz/imagemagick-cheatsheet","owner":"yangboz","description":"ImageMagick Cheat Sheet","archived":false,"fork":false,"pushed_at":"2025-02-27T09:22:32.000Z","size":285,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T13:00:01.506Z","etag":null,"topics":["image-processing","imagick","shell"],"latest_commit_sha":null,"homepage":"http://www.imagemagick.org/Usage/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yangboz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-28T03:50:18.000Z","updated_at":"2025-02-27T09:22:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"6a7b3a98-3340-4d41-89dc-2fa3a108fe53","html_url":"https://github.com/yangboz/imagemagick-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangboz%2Fimagemagick-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangboz%2Fimagemagick-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangboz%2Fimagemagick-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yangboz%2Fimagemagick-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yangboz","download_url":"https://codeload.github.com/yangboz/imagemagick-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246828503,"owners_count":20840474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-processing","imagick","shell"],"created_at":"2024-10-27T21:09:47.835Z","updated_at":"2025-04-02T14:12:03.405Z","avatar_url":"https://github.com/yangboz.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# ImageMagick Cheat Sheet\n\n**Want to improve this cheat sheet? See the [Contributing](#contributing) section!**\n\n## Table of Contents\n\n* [Why ImageMagick](#why-imagemagick)\n* [Prerequisites](#prerequisites)\n* [Installation](#installation)\n* [Basic Commands](#basic-commands)\n* [Format Conversion](#format-conversion)\n* [Resizing and Transformations](#resizing-and-transformations)\n* [Color Adjustments](#color-adjustments)\n* [Image Composition](#image-composition)\n* [Text and Annotations](#text-and-annotations)\n* [Special Effects](#special-effects)\n* [Batch Processing](#batch-processing)\n* [Animation and GIFs](#animation-and-gifs)\n* [Image Analysis](#image-analysis)\n* [Advanced Operations](#advanced-operations)\n* [Best Practices](#best-practices)\n* [Tips](#tips)\n* [Troubleshooting](#troubleshooting)\n* [Contributing](#contributing)\n* [References](#references)\n\n## Why ImageMagick\n\nUse ImageMagick® to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, HEIC, TIFF, DPX, EXR, WebP, Postscript, PDF, and SVG. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.\n\nThe functionality of ImageMagick is typically utilized from the command-line or you can use the features from programs written in your favorite language. Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), JuliaIO (Julia), L-Magick (Lisp), Lua (LuaJIT), NMagick (Neko/haXe), Magick.NET (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), magick (R), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images dynamically and automagically.\n\n## Prerequisites\n\n### ColorSpace\n\nUnderstanding color spaces like RGB, CMYK, sRGB is helpful when working with ImageMagick.\n\n### Image Processing\n\nBasic knowledge of image processing concepts helps when using the more advanced features.\n\n### Image Format\n\nFamiliarity with different image formats and their properties.\n\n## Installation\n\n### Linux (Debian/Ubuntu)\n\n```bash\napt-get install imagemagick\n```\n\n### Linux (RHEL/CentOS)\n\n```bash\nyum install imagemagick\n```\n\n### MacOS\n\n```bash\nbrew install imagemagick\n```\n\n### Memory Constraints\n\nFor memory-related issues: https://github.com/google/sanitizers/wiki/AddressSanitizer\n\n## Basic Commands\n\n### Show ImageMagick Info\n\n```bash\nconvert -version\n```\n\n```bash\nidentify -list all\n```\n\n### Verify Installation\n\n```bash\nconvert logo: logo.png\n```\n\n## Format Conversion\n\n### TIFF to PNG\n\n```bash\nmogrify -background black -format png -depth 8 *.tiff\n```\n\n### SVG to PNG\n\n```bash\nmogrify -background black -format png -depth 8 *.svg\n```\n\n### JPG to jpg (Normalize Extension)\n\n```bash\nmogrify -format jpg *.JPG\n```\n\n### WebP to JPG\n\n```bash\nconvert input.webp output.jpg\n```\n\n```bash\nmogrify -format jpg *.webp\n```\n\n### DICOM to JPG\n\n```bash\nconvert *.DCM output.jpg\n```\n\n### Multiple Images to PDF\n\n```bash\nconvert *.jpg document.pdf\n```\n\n### PDF to Images (One Per Page)\n\n```bash\nconvert -density 300 document.pdf page%03d.jpg\n```\n\n### High-Quality JPEG Conversion\n\n```bash\nconvert input.png -quality 92 -sampling-factor 4:2:0 output.jpg\n```\n\n## Resizing and Transformations\n\n### Resize by Percentage\n\n```bash\nmogrify -resize 50% *.png\n```\n\n### Resize to Exact Dimensions (Ignoring Aspect Ratio)\n\n```bash\nmogrify -resize 750x750\\! *.jpg\n```\n\n### Create a Thumbnail (Preserving Aspect Ratio)\n\n```bash\nconvert input.jpg -thumbnail 150x150 thumbnail.jpg\n```\n\n### Rotate Image\n\n```bash\nmogrify -rotate 90 *.jpg\n```\n\n### Flip (Vertical Mirror)\n\n```bash\nconvert input.jpg -flip output.jpg\n```\n\n### Flop (Horizontal Mirror)\n\n```bash\nconvert input.jpg -flop output.jpg\n```\n\n### Add Border\n\n```bash\nconvert input.jpg -border 10 -bordercolor black output.jpg\n```\n\n### Crop Image\n\n```bash\nconvert input.jpg -crop 300x200+50+50 output.jpg\n```\n\n### Split Large Image into Tiles\n\n```bash\nconvert -crop 512x512 +repage large.tif tiles/image_%d.tif\n```\n\n### Create a 3D Rotation Effect\n\n```bash\n# Requires additional scripts\n# See: http://www.fmwconcepts.com/imagemagick/rotate3D/index.php\n```\n\n## Color Adjustments\n\n### Convert to Grayscale\n\n```bash\nconvert input.jpg -colorspace Gray output.jpg\n```\n\n```bash\nfor file in *.png; do convert $file -colorspace Gray $file; done\n```\n\n### Convert from Grayscale to RGB\n\n```bash\nmogrify -type TrueColorMatte -define png:color-type=6 *.png\n```\n\n### Colorspace Conversion\n\n```bash\nconvert input.tif -colorspace RGB output.tif\n```\n\n### Apply Color Profile Conversion\n\n```bash\nconvert input.jpg -profile sRGB.icc -profile AdobeRGB.icc output.jpg\n```\n\n### Adjust Brightness and Contrast\n\n```bash\nconvert input.jpg -brightness-contrast 10x15 output.jpg\n```\n\n### Invert Colors (Create Negative)\n\n```bash\nconvert input.jpg -negate negative.jpg\n```\n\n### Make Background Transparent\n\n```bash\nconvert input.jpg -transparent white output.png\n```\n\n### Apply Sepia Tone Effect\n\n```bash\nconvert input.jpg -sepia-tone 80% sepia-output.jpg\n```\n\n## Image Composition\n\n### Append Images Horizontally\n\n```bash\nconvert *.jpg +append horizontally_appended.jpg\n```\n\n### Append Images Vertically\n\n```bash\nconvert *.jpg -append vertically_appended.jpg\n```\n\n### Create a Montage\n\n```bash\nmontage *.jpg -geometry 200x200+5+5 -background lightblue montage.jpg\n```\n\n### Create Composite with Overlay\n\n```bash\ncomposite -gravity center overlay.png base.jpg output.jpg\n```\n\n### Create Before/After Comparison\n\n```bash\nconvert before.jpg after.jpg +append comparison.jpg\n```\n\n## Text and Annotations\n\n### Add Text to Image\n\n```bash\nconvert input.jpg -fill white -pointsize 24 -gravity southeast -annotate +10+10 'Copyright 2025' output.jpg\n```\n\n### Add Watermark\n\n```bash\nconvert input.jpg -gravity southeast -stroke '#FFFFFF' -strokewidth 2 -annotate +5+5 'Watermark' -stroke none -fill '#FFFFFF88' -annotate +5+5 'Watermark' output.jpg\n```\n\n## Special Effects\n\n### Apply Blur Effect\n\n```bash\nconvert input.jpg -blur 0x8 blurred-output.jpg\n```\n\n### Create a Vignette Effect\n\n```bash\nconvert input.jpg -vignette 0x20 vignette.jpg\n```\n\n### Apply Charcoal Sketch Effect\n\n```bash\nconvert input.jpg -charcoal 2 sketch.jpg\n```\n\n### Create Polaroid-Style Image\n\n```bash\nconvert input.jpg -bordercolor white -border 10 -background black -rotate 6 -background white -polaroid 10 polaroid.jpg\n```\n\n### Apply Fisheye Effect\n\n```bash\n# Requires additional scripts\n# See: http://www.fmwconcepts.com/imagemagick/fisheye2rect/index.php\n```\n\n## Batch Processing\n\n### Convert All Images in a Folder\n\n```bash\nmogrify -format jpg *.png\n```\n\n### Apply Same Edit to Multiple Images\n\n```bash\nmogrify -resize 800x600 -quality 85 *.jpg\n```\n\n### Batch Resize and Add Watermark\n\n```bash\nfor file in *.jpg; do\n  convert \"$file\" -resize 1024x768 -fill white -pointsize 20 -gravity southeast \\\n  -annotate +10+10 'Copyright 2025' \"watermarked_$file\"\ndone\n```\n\n### Rename Files with Prefix\n\n```bash\nfor filename in *.png; do mv \"$filename\" \"prefix_$filename\"; done\n```\n\n### Rename Files by Pattern\n\n```bash\nfor f in *.jpg; do mv \"$f\" \"$(echo \"$f\" | sed s/IMG/VACATION/)\"; done\n```\n\n### Reduce JPEG Filesize\n\n```bash\nconvert -resize 100% -strip -quality 90 input.jpg output.jpg\n```\n\n### Create PNG with Transparency\n\n```bash\nconvert -resize 100% -transparent -strip -quality 90 input.png output.png\n```\n\n## Animation and GIFs\n\n### Create GIF from Sequence of Images\n\n```bash\nconvert -delay 20 -loop 0 frame*.jpg animated.gif\n```\n\n### Extract Frames from Animated GIF\n\n```bash\nconvert animated.gif -coalesce frame%03d.png\n```\n\n### Optimize GIF Filesize\n\n```bash\nconvert input.gif -layers optimize optimized.gif\n```\n\n### Resize Animated GIF\n\n```bash\nconvert input.gif -coalesce -resize 50% -layers optimize output.gif\n```\n\n## Image Analysis\n\n### Get Basic Image Information\n\n```bash\nidentify image.jpg\n```\n\n### Get Detailed Image Properties\n\n```bash\nidentify -format '%w X %h %[channels] %[bit-depth] %x x %y\\n' input.jpeg\n```\n\n### Show Verbose Image Information\n\n```bash\nidentify -verbose image.jpg\n```\n\n### Calculate Image Statistics\n\n```bash\nconvert image.jpg -format \"%[mean] %[standard-deviation]\" info:\n```\n\n### Check Image Histogram\n\n```bash\nconvert image.jpg -define histogram:unique-colors=true histogram:info:\n```\n\n## Advanced Operations\n\n### SVG Fill Replacement\n\n```bash\nfind ./ -type f -name '*.svg' | xargs -I{} sed -i_old -n -e 's/polygon fill=\"none\"/polygon fill=\"white\"/g;p;' {}\n```\n\n### Limit Output Filesize\n\n```bash\nmogrify -define jpeg:extent=5100kb *.png\n```\n\n### Create Mosaic of Images\n\n```bash\nmontage -geometry 200x200+5+5 -background lightblue *.jpg mosaic.jpg\n```\n\n## Best Practices\n\n* Use GraphicsMagick for faster processing when applicable\n* Use appropriate colorspace for your target medium\n* Be mindful of memory usage for large images\n* Set appropriate quality when saving to lossy formats\n\n## Tips\n\n* Use `-strip` to remove metadata and reduce file size\n* When working with transparency, use PNG rather than JPG\n* For complex scripts, consider using ImageMagick with shell scripting\n* Use `mogrify` for in-place edits and `convert` for creating new files\n\n## Troubleshooting\n\n* For font configuration warnings: https://stackoverflow.com/questions/24712158/how-to-solve-imagemagicks-fontconfig-warning-ignoring-utf-8-not-a-valid-regi\n* Check permissions for output directories\n* Verify that your ImageMagick installation has the required delegates for specific formats\n* If processing fails, try increasing memory limits in policy.xml\n\n## Contributing\n\nHere's how to contribute to this cheat sheet:\n\n1. Fork the repository\n2. Open README.md\n3. Make your changes\n4. Submit a pull request\n\nYour contributions will be greatly appreciated!\n\n## References\n\n* Official Website: http://www.imagemagick.org/script/index.php\n* Command-Line Options: http://www.imagemagick.org/script/command-line-options.php\n* Fred's ImageMagick Scripts: http://www.fmwconcepts.com/imagemagick/\n* GraphicsMagick: http://www.graphicsmagick.org/formats.html\n* Legacy Forum: https://legacy.imagemagick.org/discourse-server/\n* Crop \u0026 Tile Examples: https://legacy.imagemagick.org/Usage/crop/#crop_tile\n* Montage Usage: https://legacy.imagemagick.org/Usage/montage/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangboz%2Fimagemagick-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyangboz%2Fimagemagick-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyangboz%2Fimagemagick-cheatsheet/lists"}