Nono.MA

MAY 28, 2022

You can ask ImageMagick for details of image files with the identify. Say, their dimensions (width and height), their resolution (pixels-per-inch), or many other details.

You can run the identify by itself to get a series of default details.

The Identify command

identify image.jpg
# image.jpg JPEG 1600x1659 1600x1659+0+0 8-bit sRGB 475062B 0.010u 0:00.002

The -verbose flag

Or even to obtain greater details with the -verbose flag. (Note that this command returns more than 300 lines of information per image, so I'm omitting most of what was returned.)

identify -verbose image.jpg
# Image:
#  Filename: image.jpg
#  Format: JPEG (Joint Photographic Experts Group JFIF format)
#  Mime type: image/jpeg
#  Class: DirectClass
#  Geometry: 1600x1659+0+0
#  Resolution: 200x200
#  ...

Width and Height of a single image

identify -format "%wx%h" image.jpg
# 1600x1659

Width and Height of multiple images in a directory

identify -format "%wx%h\n" *.jpg
# 1983x1969
# 1912x1803
# 2173x2126
# 1807x1669
# ...

Dimensions and names

identify -format "%wx%h - %f\n" *.jpg
# 1983x1969 - image-01.jpg
# 1912x1803 - image-02.jpg
# 2173x2126 - image-03.jpg
# 1807x1669 - image-04.jpg
# ...

For reference, here are ImageMagick's identify docs.

OCTOBER 1, 2020

Note: This document is incomplete and work-in-progress.

Here are different ways to convert (or rasterize) SVG graphics to PNG.

Librsvg

brew install librsvg

Then the rsvg-convert command should be available in your terminal.

rsvg-convert --help

# Usage:
#   rsvg-convert [OPTION…] [FILE...] - SVG Converter
# 
# Help Options:
#   -?, --help                                                  Show help options
# 
# Application Options:
#   -d, --dpi-x=<float>                                         pixels per inch [optional; defaults to 90dpi]
#   -p, --dpi-y=<float>                                         pixels per inch [optional; defaults to 90dpi]
#   -x, --x-zoom=<float>                                        x zoom factor [optional; defaults to 1.0]
#   -y, --y-zoom=<float>                                        y zoom factor [optional; defaults to 1.0]
#   -z, --zoom=<float>                                          zoom factor [optional; defaults to 1.0]
#   -w, --width=<int>                                           width [optional; defaults to the SVG's width]
#   -h, --height=<int>                                          height [optional; defaults to the SVG's height]
#   -f, --format=[png, pdf, ps, eps, svg, xml, recording]       save format [optional; defaults to 'png']
#   -o, --output                                                output filename [optional; defaults to stdout]
#   -i, --export-id=<object id>                                 SVG id of object to export [optional; defaults to exporting all objects]
#   -a, --keep-aspect-ratio                                     whether to preserve the aspect ratio [optional; defaults to FALSE]
#   -b, --background-color=[black, white, #abccee, #aaa...]     set the background color [optional; defaults to None]
#   -s, --stylesheet                                            Filename of CSS stylesheet
#   -u, --unlimited                                             Allow huge SVG files
#   --keep-image-data                                           Keep image data
#   --no-keep-image-data                                        Don't keep image data
#   -v, --version                                               show version information

ImageMagick

InkScape

brew cask install inkscape
inkscape --action-list

# action-list         :  Print a list of actions and exit.
# convert-dpi-method  :  Import DPI convert method.
# export-area         :  Export area.
# export-area-drawing :  Export drawing area.
# export-area-page    :  Export page area.
# export-area-snap    :  Export snap area to integer values.
# export-background   :  Export background color.
# export-background-opacity:  Export background opacity.
# export-do           :  Do export.
# export-dpi          :  Export DPI.
# export-filename     :  Export file name.
# export-height       :  Export height.
# export-id           :  Export id(s).
# export-id-only      :  Export id(s) only.
# export-ignore-filters:  Export ignore filters.
# export-latex        :  Export LaTeX.
# export-margin       :  Export margin.
# export-overwrite    :  Export over-write file.
# export-pdf-version  :  Export PDF version.
# export-plain-svg    :  Export as plain SVG.
# export-ps-level     :  Export PostScript level.
# export-text-to-path :  Export convert text to paths.
# export-type         :  Export file type.
# export-use-hints    :  Export using saved hints.
# export-width        :  Export width.
# file-close          :  Close active document.
# file-new            :  Open new document using template.
# file-open           :  Open file.
# inkscape-version    :  Print Inkscape version and exit.
# no-convert-baseline :  Import convert text baselines.
# object-set-attribute:  Set or update an attribute on selected objects. Usage: object-set-attribute:attribute name, attribute value;
# object-set-property :  Set or update a property on selected objects. Usage: object-set-property:property name, property value;
# object-to-path      :  Convert shapes to paths.
# object-unlink-clones:  Unlink clones and symbols.
# open-page           :  Import page number.
# query-all           :  Query 'x', 'y', 'width', and 'height'.
# query-height        :  Query 'height' value(s) of object(s).
# query-width         :  Query 'width' value(s) of object(s).
# query-x             :  Query 'x' value(s) of selected objects.
# query-y             :  Query 'y' value(s) of selected objects.
# quit-inkscape       :  Immediately quit Inkscape.
# select              :  Select by ID (Deprecated)
# select-all          :  Select all. Options: 'all' (every object including groups), 'layers', 'no-layers' (top level objects in layers), 'groups' (all groups including layers), 'no-groups' (all objects other than groups and layers, default).
# select-by-class     :  Select by class
# select-by-element   :  Select by SVG element (e.g. 'rect').
# select-by-id        :  Select by ID
# select-by-selector  :  Select by CSS selector
# select-clear        :  Selection clear
# select-invert       :  Invert selection. Options: 'all', 'layers', 'no-layers', 'groups', 'no-groups' (default).
# select-list         :  Print a list of objects in current selection.
# system-data-directory:  Print system data directory and exit.
# transform-remove    :  Remove any transforms from selected objects.
# transform-rotate    :  Rotate selected objects by degrees.
# transform-scale     :  Scale selected objects by scale factor.
# transform-translate :  Translate selected objects (dx,dy).
# unselect            :  Unselect by ID (Deprecated)
# unselect-by-id      :  Unselect by ID
# user-data-directory :  Print user data directory and exit.
# vacuum-defs         :  Remove unused definitions (gradients, etc.).
# verb                :  Execute verb(s).
# verb-list           :  Print a list of verbs and exit.
# window-close        :  Close the active window.
# window-open         :  Open a window for the active document. GUI only.
inkscape --export-format="png" in.svg

svgexport

npm install -g svgexport
svgexport infile.svg outfile.png

Cairo

cairosvg

dom-to-image

To-do.

Want to see older publications? Visit the archive.

Listen to Getting Simple .