diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-11-24 11:25:32 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-11-24 12:27:18 -0700 |
commit | b75a27ad88ab1a96cc8021394bd0f33e4da90bc0 (patch) | |
tree | a08169a998b61dceee22edcc1f284653569be1b5 /bin/blogdims | |
parent | 142c29d54b8b7d14fc1868d81e7461c804a31dc9 (diff) | |
download | dotfiles-b75a27ad88ab1a96cc8021394bd0f33e4da90bc0.tar.gz |
blogdims script
Diffstat (limited to 'bin/blogdims')
-rwxr-xr-x | bin/blogdims | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/blogdims b/bin/blogdims new file mode 100755 index 00000000..26f3aec4 --- /dev/null +++ b/bin/blogdims @@ -0,0 +1,31 @@ +#!/usr/bin/python + +# blog image aspect ratio calculator + +from __future__ import division # so that dividing two integers returns a float +import sys +import os +from PIL import Image # apt-get install python-imaging + +def main(): + if len(sys.argv) < 2: + sys.exit('%s: usage: %s IMAGE' % sys.argv[0]) + if not os.path.exists(sys.argv[1]): + sys.exit('%s: file %s not found' % (sys.argv[0], sys.argv[1])) + + img = Image.open(sys.argv[1]) + img_width, img_height = img.size + + if img_width > img_height: + new_width = "500" + new_height = (500 / img_width) * img_height + new_height = str(round(new_height, 0))[:-2] + else: + new_height = "500" + new_width = (500 / img_height) * img_width + new_width = str(round(new_width, 0))[:-2] + + print "[[!img blog/img/" + os.path.basename(sys.argv[1]) + " size=" + new_width + "x" + new_height + "]]" + +if __name__ == "__main__": + main() |