Skip to content

Instantly share code, notes, and snippets.

@jcracknell
Created April 7, 2014 18:31
Show Gist options
  • Save jcracknell/10027521 to your computer and use it in GitHub Desktop.
Save jcracknell/10027521 to your computer and use it in GitHub Desktop.
#!/bin/bash
#==========
# Uses the GIMP to set the specified DPI value on the specified image without
# changing the dimensions of the image.
#
# This is useful as Inkscape provides no means of changing the DPI of an exported
# image without altering its pixel count, and also defaults to 90dpi.
#
# Note that gimp-console must be in your $PATH.
dpi=$1
img=$2
if [ "$dpi" -a "$img" ]; then
echo "Setting DPI of \"$img\" to $dpi... ";
gimp-console -i -b "
(let* (
(image (car (gimp-file-load RUN-NONINTERACTIVE \"$img\" \"$img\")))
(drawable (car (gimp-image-get-active-layer image)))
) (
(gimp-image-set-resolution image $dpi $dpi)
(gimp-file-save RUN-NONINTERACTIVE image drawable \"$img\" \"$img\")
(gimp-quit 0)
))
";
else
echo "Usage: $0 <dpi> <img>";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment