Skip to content

Instantly share code, notes, and snippets.

@gordonmeyer
Last active December 15, 2015 08:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gordonmeyer/5230354 to your computer and use it in GitHub Desktop.
Save gordonmeyer/5230354 to your computer and use it in GitHub Desktop.
This OS X bash script takes an image file as a parameter. The width and height of the image are identified, and a fully-qualified img tag is output. Note that the location of the image on the remote server is hardcoded and will need to be changed for your site. Read more about this script at: http://www.gordonmeyer.com/2013/03/a-script-to-automa…
#!/bin/bash
#gordonmeyer.com March 23, 2013
#usage: imgref filename
#output: <img> tag
#requires: OS X
#credits: http://superuser.com/questions/273059/get-pixel-dimensions-of-a-png-on-my-mac
filename=$1
if [ ! -f "$filename" ] ; then
echo "$filename not found!";
exit 1
fi
bname=$( basename "$filename")
prfx="<img src=\"http://www.chicagomagicstudio.com/map/gfx/"
h=$( sips -g pixelHeight "$filename" | tail -n1 | cut -d" " -f4 )
w=$( sips -g pixelWidth "$filename" | tail -n1 | cut -d" " -f4 )
theref=$( echo $prfx$bname\" width=\"$w\" height=\"$h\"\>\</br\>TITLE)
echo $theref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment