Created
April 21, 2014 19:00
-
-
Save spacedman/11152792 to your computer and use it in GitHub Desktop.
Tweak the DPI on an image file so that it specifies it to be a certain number of inches.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# take an image and a desired width in inches, set the DPI | |
# | |
input=$1 | |
width=$2 | |
echo $input | |
echo $width | |
# get the current DPI, divide by width to get new DPI | |
density=`identify -format "%w" $input | awk "{print \\$0/$width}"` | |
echo $density | |
convert -units PixelsPerInch $input -density $density $input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage. Create standard rose png file from imagemagick:
$ convert rose: rose.png
$ identify -verbose rose.png | grep Print
Print size: 0.972222x0.638889
$ ../setdpi.sh rose.png 2
rose.png
2
35
$ identify -verbose rose.png | grep Print
Print size: 5.07983x3.33817
$ identify -verbose rose.png | grep Units
Units: PixelsPerCentimeter
5.07cm is 2 inches.
Now with jpg:
$ convert rose: rose.jpg
$ identify -verbose rose.jpg | grep Print
Print size: 0.972222x0.638889
$ ../setdpi.sh rose.jpg 2
rose.jpg
2
35
$ identify -verbose rose.jpg | grep Print
Print size: 2x1.31429
$ identify -verbose rose.jpg | grep Units
Units: PixelsPerInch
Jpegs units are pixels per inch so print size is 2x1.31424 inches.