Resize

Keep aspect ration

# resize all if height > 100
magick mogrify -resize x100^> *png
# resize all if width < 100
magick mogrify -resize 100^< *png

Montage

center, take care of the number of pictures (here horizontal 12 pictures), need to be resize with height before with this examples magick montage *.png -tile 12x1 -gravity center Merge.png

horizontal magick *.png +append horizontal.png magick *.png -append vertical.png

Sharpen

Source

magick Bild_1.jpg -sharpen 0x5 Bild_1.png

Convert

Image to matrice - cut the image in pieces

Source

convert image.jpg -crop 50%x50% +repage piece_%d.jpg

flex to single tif with regex

magick.exe convert %input% -set filename:f "%%t_%%s" +adjoin "%%[filename:f].tif"

From to (jpg, pdf …), rotate …

magick mogrify -format jpg *.ppm
mogrify -format pdf *jpg
mogrify -rotate "270" *jpg

jpg to pdf

in 1 folder, 1 jpg for 1 page in a pdf

:: Will convert all jpg from a folder in a page in a pdf
for /F "usebackq delims=" %A in (`ls ^|grep -s jpg ^| tr "\n" " "`) do convert -quality 85 %A output.pdf

pdf to png/jpg

Source Stackoverflow

magick convert -density 300 -trim in.pdf -quality 100 out.png

-density 300 sets the dpi that the PDF is rendered at. -trim removes any edge pixels that are the same color as the corner pixels. -quality 100 sets the JPEG compression quality to the highest quality.

crop

magick convert input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif
magick convert giphy.gif -coalesce -repage 0x0 -crop 84x139+100+149 +repage output.gif

You can use qimgv to get the dimension of the crop easily

Source

remove background

Option 1

magick convert input.gif -transparent black g%01d.png
magick convert -dispose background g*.png output.gif

Part of the source and official manual

Option 2

or even better, adapt fuzz

magick convert charlie.png -fill none -fuzz 50% -draw "color 0,0 floodfill" charlie2.png

Other example with this Gif

magick convert in.gif -resize 50% in2.gif # resize 
magick convert in2.gif g%01d.png # export each frame
del g00.png # remove first one that was the background
magick convert -delay 5 g*.png -delay 600 g17.png out.gif # keep last frame longer

creating this:

Option 3

Really good results

 magick convert Bild_1c.png -fuzz 80% -transparent white Bild_1d.png

Combine with Resize, sharpen

magick convert Bild_1.jpg -resize 500x Bild_1b.png 
magick Bild_1b.png -sharpen 0x20 Bild_1c.png 
magick convert Bild_1c.png -fuzz 80% -transparent white Bild_1d.png

Replace color

# Adapt the fuzz 
magick input.png -fuzz 80% -fill black     -opaque white       output1.png
magick input.png -fuzz 80% -fill "#000000" -opaque "#ffffff"   output2.png

# keep the transparency level
magick input.png  -channel RGB -auto-level    +level-colors black    output3.png

-input: input

  • ouput1: output1
  • ouput2: output2
  • ouput3: output3

Check this out to replace colors to a certain ton and keep transparency

Trim empty pixels

magick img.png -define trim:edges=north,south -trim +repage img2.png
magick mogrify -define trim:edges=north,south -trim +repage -path edited\images\dir *.png

Source

Batch examples

Level brightness

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

echo Choose where your jpg files are (choose 1 jpg):

:: file choose and get dir
set dialog="about:<input type=file id=FILE><script>FILE.click();new ActiveXObject
set dialog=%dialog%('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);
set dialog=%dialog%close();resizeTo(0,0);</script>"

for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "input=%%p"
for /F %%i in ("%input%") do @set dir=%%~dpi
for /F %%i in ("%input%") do @set drive=%%~di

%drive%
cd %dir%


:: User input number of channel

set /p channel="At which level do you wanna set the white point ? (20 mean 20 percent of the actual, just test and MAKE A COPY OF YOUR FILE) : "
set /a channel=channel

:: give info on what will be done
dir /a-d /b "*jpg" | find /c "jpg" > temp
set /p nfiles= < temp
set /a nfiles=nfiles
set /a xfile=1
del temp

set /p tt=%nfiles% jpg will be processed, type Enter to continue.


:: convert in tiff and rename it
FOR /F "delims=" %%a IN ('dir /a-d /b "*jpg"') DO (
    H:\TEMP\Software\ImageMagick-7.0.8-Q16\magick.exe convert %%a -level "0%%,%channel%%%,1" %%a
    echo 1 more done ...
)

Flex files to tiff

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

echo Choose where your flex files are (choose 1 flex):

:: file choose and get dir
set dialog="about:<input type=file id=FILE><script>FILE.click();new ActiveXObject
set dialog=%dialog%('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);
set dialog=%dialog%close();resizeTo(0,0);</script>"

for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "input=%%p"
for /F %%i in ("%input%") do @set dir=%%~dpi
for /F %%i in ("%input%") do @set drive=%%~di

%drive%
cd %dir%
mkdir TIFF

:: User input number of channel

set /p channel="How many Channel you have ? "
set /a channel=channel

:: give info on what will be done
dir /a-d /b "*flex" | find /c "flex" > temp
set /p nfiles= < temp
set /a nfiles=nfiles
set /a xfile=1
del temp

set /p tt=%nfiles% flex will be processed, type Enter to continue.


:: convert in tiff and rename it
FOR /F "delims=" %%a IN ('dir /a-d /b "*flex"') DO (
    H:\TEMP\Software\ImageMagick-7.0.8-Q16\magick.exe convert %%a -set filename:f "%%t_%%s" +adjoin "TIFF\%%[filename:f].tif"
    dir /b "*.tif" | find /c "%%~na" > temp
    set /p howmany= < temp
    set /a howmany=!howmany!
    del temp
    set /a loopfi=howmany/channel
    :: order dir by date /od
    cd TIFF
    FOR /F "delims=" %%b IN ('dir /a-d /b /od "%%~na*tif"') DO (
        FOR /l %%c IN (1, 1, !loopfi!) DO (
            FOR /l %%d IN (1, 1, %channel%) DO (
                ren %%b TIFF\%%~na_ch%%d_fi%%c.tif

            )
        )
    )
    cd ..
    echo !xfile! flex / !nfiles!
)

reduce number of frame gif

# check number of frames
convert input.gif[-1] -format %[scene] info:
    # or
     exiftool input.gif | grep "Frame Count"
# identify frame rate
gifsicle -I input.gif | grep delay
# use gifsicle to convert in lower colors
gifsicle --colors=255 input.gif -o output.gif
# remove some frames
# source: https://graphicdesign.stackexchange.com/a/20937/157170
gifsicle -U output.gif `seq -f "#%g" 0 2 2569` -O2 -o output2.gif
# recheck
convert output2.gif[-1] -format %[scene] info:
# set again speed, in 100 of second. Here identify showed :     disposal asis delay 0.07s
# so I set to 14/100 seconds
gifsicle -d 14 output2.gif -o output3.gif

mp4 to gif

# check fps:
exiftool Uphill.mp4 | grep -i "video frame"
# calculate the delay
echo 100/fps | bc
# convert with Magick
convert -delay 3 GetReady2.mp4 -loop 0 GetReady2.gif