🖥️convert

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the convert command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                 ██████╗ ██████╗ ███╗   ██╗██╗   ██╗███████╗██████╗ ████████╗
#                ██╔════╝██╔═══██╗████╗  ██║██║   ██║██╔════╝██╔══██╗╚══██╔══╝
#                ██║     ██║   ██║██╔██╗ ██║██║   ██║█████╗  ██████╔╝   ██║   
#                ██║     ██║   ██║██║╚██╗██║╚██╗ ██╔╝██╔══╝  ██╔══██╗   ██║   
#                ╚██████╗╚██████╔╝██║ ╚████║ ╚████╔╝ ███████╗██║  ██║   ██║   
#                 ╚═════╝ ╚═════╝ ╚═╝  ╚═══╝  ╚═══╝  ╚══════╝╚═╝  ╚═╝   ╚═╝   
                                                                             
                                                                             
                                                                            
# To resize an image to a fixed width and proportional height:
convert original-image.jpg -resize 100x converted-image.jpg

# To resize an image to a fixed height and proportional width:
convert original-image.jpg -resize x100 converted-image.jpg

# To resize an image to a fixed width and height:
convert original-image.jpg -resize 100x100 converted-image.jpg

# To resize an image and simultaneously change its file type:
convert original-image.jpg -resize 100x converted-image.png

# To resize all of the images within a directory:
# To implement a for loop:
for file in `ls original/image/path/`;
    do new_path=${file%.*};
    new_file=`basename $new_path`;
    convert $file -resize 150 conerted/image/path/$new_file.png;
done

# Make text annotatation (text = Flower)
convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg

# Crop an image
convert flower.jpg -crop 128×128+50+50 flower_crop.jpg

# Rotate an image
convert flower.jpg -rotate 45 flower_rotate45.jpg

# Add a border
convert -border 1x1 -bordercolor "#FFFFFF" image.png new-image.png

# Convert PNG to JPEG (with 70% quality)
convert -quality 70 image.png new_image.jpg

#==============================#
# CMD convert
#==============================##==============================#
convert -size 500x300 xc:white -fill xc:'#CABB1E' -draw "polygon 35,140 115,130 150,55 310,55 350,130 460,150 460,210 35,210" cabbie.png
#

convert +level-colors Firebrick, me.jpg oldme.jpg
# Mark Zuckerburg could've saved a billion if he knew about ImageMagick. (Instagram)

convert -size 1280x720 plasma:green-blue background.png
# Create a 1280x720 color plasma image. Different each time. Uses ImageMagick

convert -size 413x314 xc:tan -fill red -pointsize 200 -gravity center -draw "text 0,0 '3.14'" -flop pie.png
# Req. ImageMagick #pi #piday

convert -size 2420x1580 plasma:fractal -blur 2x2 -swirl 270 -crop 1920x1080+250+250 swirlbg.png 
# Swirly plasma background. Uses ImageMagick

scanimage --format=tiff --mode Color | convert tiff:- ~/Scans/$(date "+%Y-%m-%d_%H:%M:%S").jpg 
# Scan directly w/ cur date.

convert bluethumb.png -modulate 100,100,50 greenthumb.png 
# Change the hue of an image by -90 degrees. 50 = ( -90 * 100/180 ) + 100

##############
## Converting Images to Movie
###############################

# How to turn a series of numbered images into an mpeg or avi movie using free software This is mainly oriented towards Unix systems (MacOSX / Linux / Unix) but some things also work on Windows

# It is assumed that the image files are something like name001.jpg, name002.jpg, name003.jpg, etc. Here is a quick summary and links to fuller information: for more extensive discussion and other options see here, with specific information about using ffmpeg here and about ppmtompeg here.

#-----------------------------------------------------#
# Step 0: Getting the image files in the right format #
#-----------------------------------------------------#

# It may be necessary to convert your image files before encoding them. For example, mencoder seems to need jpgs. The most convenient command for this is "convert", part of the ImageMagick package that comes with most Linux distributions and for the Mac can be downloaded using fink.

# e.g., to convert a single ppm image to jpg:  
convert -quality 100 image123.ppm image123.jpg

# For a series of images, use something like:

for f in *.ppm; do convert -quality 100 $f  `basename $f .ppm`.jpg; done
# (if this does not work on the command line, put into an ascii file e.g., script then run  using 'sh script').

# Use 'convert'
#--------------------------#

# convert is part of the ImageMagick package, which comes with many Linux distributions. For Mac it can be downloaded using fink.
# mpeg: To convert images to an mpeg movie it is necessary to also install mpeg2encode, which is available from the same places (note, this may be in the 'unstable' branch of fink). To convert a series of numbered ppm files to an mpg movie:

convert -delay 6 -quality 95 test*ppm movie.mpg
#    -delay and -quality flags are optional. If -delay is set >4, it will add extra frames to make the movie run more slowly, thereby increasing the size of the file. The default quality is 75 and maximum is 100.

# animated gif: e.g.,

convert -delay 20 test*ppm movie.gif
# After this, the animated gif can be converted to mov format using quicktime pro.

convert -size 150x100 xc:white -fill red -draw 'circle 75,50 75,75' flagofjapan.png 
# Make the flag of Japan with ImageMagick.

convert 1.jpg <( curl http://wttr.in/Oymyakon_tqp0.png … ) -geometry +50+50 -composite 2.jpg
# How to add weather data to your photos

convert spin.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "credit.png"' -layers Optimize spin2.gif 
# Add image to anim gif.

# append two imgaes horizontal
convert +append pic1.jpg pic2.jpg output.jpg 

#create ICO file with more than one image
# requires imagemagick. -background transparent is of course optional. for older version use:

convert image.png  -bordercolor white -border 0 \
      \( -clone 0 -resize 16x16 \) \
      \( -clone 0 -resize 32x32 \) \
      \( -clone 0 -resize 48x48 \) \
      \( -clone 0 -resize 64x64 \) \
      -delete 0 -alpha off -colors 256 favicon.ico

or
convert -resize x16 -gravity center -crop 16x16+0+0 input.png -flatten -colors 256 favicon.ico

convert -background transparent input.png -define icon:auto-resize=16,32,48,64,128 favicon.ico

# Celebrate Friday in style
T="It's Friday\!";a="-annotate +25+65";convert -size 420x100 xc:lightblue -font Candice -pointsize 72 -fill white -stroke black -strokewidth 15 $a "$T" -stroke white -strokewidth 10 $a "$T" -stroke black -strokewidth 5 $a "$T" -stroke none $a "$T" 

# How to create a favicon from an image - Here are all the available options for the imagemagick convert command. https://www.imagemagick.org/script/command-line-options.php
convert <your-image-here> -define icon:auto-resize=256,64,48,32,16 favicon.ico

convert -size 1920x1080 plasma:fractal background.png 
# Create an HD color plasma image. Different each time. Uses ImageMagick

convert +level-colors Firebrick, me.jpg oldme.jpg 
# Apply a moody color filter to your photo.

convert -evaluate-sequence Min $( for i in $( seq 34 7 99 ) ; do echo $i.png ; done ) every7th-frame.jpg 
# http://bit.ly/19pNPV9 

# Repeat the previous command but with a string replacement
^geomtry^geometry
# Explanation: This can be very useful for example after a mistyped command like this:
convert -crop 745x845+0+150 my_logo.png -geomtry 400x my_logo2.png
^geomtry^geometry
        # "-geomtry" should have been "-geometry", the one-liner above will re-run the command with a replacement that fixes the typo.

# Create a thumbnail from the first page of a PDF file
convert -thumbnail x80 file.pdf[0] thumb.png
# Explanation: 
    # convert is part of ImageMagick image manipulation tool
    # -thumbnail x80 means create a thumbnail image of height 80 pixels, the width will be automatically chosen to make the image proportional
    # The [0] is to create a thumbnail for the first page only, without that a thumbnail image would be created for each page in the pdf file
# To do this for all PDF files in a directory tree:
find /path/to/dir -name '*.pdf' -exec convert -thumbnail x80 {}[0] {}-thumb.png \;
# Limitations: Requires the ImageMagick image manipulation tool.

# Create a transparent image of given dimensions
convert -size 100x100 xc:none transparency.png
# Explanation: 
    # convert is a tool that's part of the ImageMagick image manipulation library
    # -size 100x100 specifies the dimensions of the image to create
    # xc:none is a symbolic source image, indicating to convert "from nothing"
    # transparency.png is the destination filename, the image format is automatically determined by the extension
# Limitations: Requires the ImageMagick image manipulation library.

# Take screenshots as needed by clicking on a window, then turn them into an animated gif with half-second frame lengths.
for i in {01..20}.png ; do scrot -s $i ; echo $i ; done ; convert -delay 50 {01..20}.png -layers Optimize anim.gif 

# chmod 777
convert -delay 100 0.png -delay 1 $(seq -f %g.png 1 3 119) -delay 200 120.png -delay 1 $(seq -f %g.png 119 -4 1) -layers optimize -loop 0 anim777.gif 

C="254,278" PP="30,362 212,44 350,287 272,287 212,187 70,430"; convert -size 500x500 xc:\#101 -alpha on -stroke green -strokewidth 2 -fill \#1C1 -draw "polygon $PP" -distort SRT "$C 120" -fill \#1A1 -draw "polygon $PP" -distort SRT "$C 120" -fill \#181 -draw "polygon $PP" mce.png

T="Text";a="-annotate +0+0";convert -size 420x300 -gravity center radial-gradient:white-purple -font FontName -pointsize 72 -fill yellow -stroke pink -strokewidth 15 $a "$T" -stroke yellow -strokewidth 10 $a "$T" -stroke orange -strokewidth 5 $a "$T" -stroke none $a "$T" file.png

n=0;p=3.14159;for i in {0..360};do x=$(bc -l <<<"150*$p*2/360)*$i)"|numround);y=$(bc -l <<<"150*$p*c(($p*2/360)*$i)"|numround);echo $x,$y;done|while read c;do f=$(printf "%03d" $n);convert -size 300x300 xc:black -stroke green -draw "line 150,150 $c" $f.gif;n=$[n+1];done # Radar

# numround isn't necessary
for i in {0..360}; do c=`bc -l <<< "scale=3;pi=4*a(1);t=$i*pi/180;x=150*(1+s(t));y=150*(1+c(t));print x,\",\",y"`; convert -size 300x300 xc:black -stroke green -draw "line 150,150 $c" `printf %03d $i`.gif; done 

# Concat jpgs into pdf – requires imagemajick
convert .jpg career-guide-private-equity.pdf

# Help your #Youtube videos standout in the crowd with these black thumbnails. Thanks Joshua ;) 
convert -size 192x108 xc:black blackthumbnail.png 

#==============================##==============================#
# CMD convert						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░