My favorites | Sign in
Project Logo
                
Search
for
Updated Dec 03, 2007 by jonahboss
Drinkme  
An Image resizing microapp

Introduction

Drinkme is a microapp for basic image resizing.

You POST an image and a size, and it resizes the image to that size and returns it. not very complicated.

REST API

There is only one action: a POST to /resize. The only required parameter is image which should be an image file in a multipart/form-encoded format. There are two optional parameters: resize, and square which are explained below.

A sample curl session looks like:

  $ curl -X POST  -F "image=@MyImage.jpg" \
    http://drinkme.example.com/resize > thumb.jpg

The default size is 100 pixels. It will scale the image so its longest side is at most 100 pixels, while preserving the aspect ratio.

You can specify a different size with a size parameter like so:

  $ curl -X POST  -F size=200 -F "image=@MyImage.jpg" \
    http://drinkme.example.com/resize > thumb200.jpg

Drinkme will also make square thumbnails. Ie, it will crop the image so its width and height are equal and then scale it to the specified size. This is disabled by default but can be enabled by sending a non-zero value for the 'square' parameter:

  $ curl -X POST  -F square=1 -F "image=@MyImage.jpg" \
    http://drinkme.example.com/resize > square.jpg

From python, you can use the convenient restclient:

>>> from restclient import POST
>>> image = open("big_image.jpg", 'r').read()
>>> thumb_file = open("big_image_thumb.jpg", 'w')
>>> out = POST('http://drinkme.example.com/resize', 
               files= { 'image' : { 'file' : image_file , 'filename' : image }},
               async=False)
>>> thumb_file.write(out)
>>> thumb_file.close()

That's pretty much it. Currently only jpg, gif, and png images are supported.

Requirements

All other requirements are bundled with Drinkme and will be automatically installed with the included init.sh script.

Installation

(Tested on Ubuntu Linux (Feisty), but should work anywhere that Paste works.)

To install, check out code:

  $ svn co http://microapps.googlecode.com/svn/drinkme/trunk/ drinkme

initialize a workingenv:

  $ cd drinkme
  $ ./init.sh .

init.sh takes the directory to put the workingenv in as its only argument. It will create a workingenv and install all the necessary (and included) eggs into it.

edit development.ini, prod.ini, or copy one of those to a different file and configure to your liking (change port #, etc.)

run it:

  $ ./start.sh . prod.ini

Drinkme is also a WSGI/Paste app, so you should be able to combine it with any other WSGI frameworks, servers, etc. in a standard manner.

Credits

Drinkme was developed by Anders Pearson at the Columbia Center For New Media Teaching and Learning (http://ccnmtl.columbia.edu/).


Comment by n.bruenggel, Jun 10, 2008

did not work for me..

(working-env)user@host:~/Playground/drinkme$ easy_install -H None -f eggs eggs/.egg Processing Cheetah-1.0-py2.5-linux-x86_64.egg creating /home/user/Playground/drinkme/working-env/lib/python2.5/Cheetah-1.0-py2.5-linux-x86_64.egg Extracting Cheetah-1.0-py2.5-linux-x86_64.egg to /home/user/Playground/drinkme/working-env/lib/python2.5

File "/home/user/Playground/drinkme/working-env/lib/python2.5/Cheetah-1.0-py2.5-linux-x86_64.egg/Cheetah/NameMapper?.py", line 146
from future import generators
SyntaxError?: from future imports must occur at the beginning of the file

File "/home/user/Playground/drinkme/working-env/lib/python2.5/Cheetah-1.0-py2.5-linux-x86_64.egg/Cheetah/Tests/NameMapper?.py", line 15
from future import generators

SyntaxError?: from future imports must occur at the beginning of the file

Adding Cheetah 1.0 to easy-install.pth file Installing cheetah-compile script to /home/user/Playground/drinkme/working-env/bin/ Installing cheetah script to /home/user/Playground/drinkme/working-env/bin/

Installed /home/user/Playground/drinkme/working-env/lib/python2.5/Cheetah-1.0-py2.5-linux-x86_64.egg Processing dependencies for Cheetah==1.0 Searching for Cheetah==1.0

Link to http://pypi.python.org/simple/Cheetah/ BLOCKED by --allow-hosts

Couldn't find index page for 'Cheetah' (maybe misspelled?) Scanning index of all packages (this may take a while)

Link to http://pypi.python.org/simple/ BLOCKED by --allow-hosts

No local packages or download links found for Cheetah==1.0 error: Could not find suitable distribution for Requirement.parse('Cheetah==1.0') (--always-copy skips system and development eggs)


Sign in to add a comment
Hosted by Google Code