convert

From RaySoft

The convert program is a member of the ImageMagick suite of tools. Use it to convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.[1]

Documentation

Parameters

-alpha TYPE
Gives control of the alpha/matte channel of an image.
-background COLOR
Set the background COLOR.
-border GEOMETRY
Surround the image with a border of color.
-bordercolor COLOR
Set the border COLOR.
-colors NUMBER
Set the preferred NUMBER of colors in the image.
-define KEY{=VALUE} [...]
Add specific global settings generally used to control coders and image processing operations.
-define 'filter:support=RADIUS'
Set the filter support RADIUS. Defines how large the filter should be and thus directly defines how slow the filtered resampling process is.
-define 'png:compression-filter=VALUE'
Valid VALUEs are 0 through 9. 0-4 are the corresponding PNG filters, 5 means adaptive filtering except for images with a colormap, 6 means adaptive filtering for all images, 7 means MNG 'loco' compression, 8 means Z_RLE strategy with adaptive filtering, and 9 means Z_RLE strategy with no filtering.
-define 'png:compression-level=VALUE'
Valid VALUEs are 0 through 9, with 0 providing the least but fastest compression and 9 usually providing the best and always the slowest.
-delete INDEX
Delete the images specified by index, from the image sequence.
-fill COLOR
COLOR to use when filling a graphic primitive.
-font NAME
Set the font to use when annotating images with text, or creating labels.
-interlace TYPE
The TYPE of interlacing scheme.
-pointsize NUMBER
Pointsize of the Postscript, OPTION1, or TrueType font.
-quality LEVEL
JPEG/PNG compression LEVEL.
-resize GEOMETRY
Resize an image to GEOMETRY.
-strip
Strip the image of any profiles or comments.
-trim
Trim an image.

Examples

Convert an image to another format
if type -P 'convert' >'/dev/null' 2>&1; then
  my::convert_images() {
    for old_file in *.$(sed 's/./[&\u&]/g' <<< "$1"); do
      local new_file="${old_file,,}"; new_file="${new_file/%$1/$2}"

      if [[ -f "${new_file}" ]]; then
        my::carp "'${new_file}' already exists"
        continue
      fi

      if convert -strip "${old_file}" "${new_file}" >'/dev/null' 2>&1; then
        echo "Convert '${old_file}' => '${new_file}'"

        rm "${old_file}"
      else
        my::carp "'${file}' can't be converted"
        return 1
      fi
    done
  }

  alias my::gif2png='my::convert_images "gif" "png"'
  alias my::png2jpg='my::convert_images "png" "jpg"'
fi
Create a favicon[2]
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'

References