Image renderer and cacher in Erlang. It supports:
- resizing based on the device size (using WURFL Cloud to perform lookups),
- image convertion using the
convert
utility provided by ImageMagick, - serving of locally hosted images using the
file://<path_to_file>
scheme, and - serving of Amazon S3 (privately) hosted images using the
s3://<bucket>/<key>
scheme, which builds the required signed URL.
If the image is located at "http://www.google.co.za/images/srpr/logo3w.png", make the following call:
http://localhost:8000/render?url=http%3A%2F%2Fwww.google.co.za%2Fimages%2Fsrpr%2Flogo3w.png
The image will be retrieved, cached and served the first time it is request. Thereafter it will simply be served from the cache.
Note that:
- Local files can be served using the "file://" scheme.
- Files hosted on Amazon S3 can be served using the
s3://
scheme. - Source image caching can be disabled in the config file if necessary.
If you require the image to have a restricted width or height, it can be specified:
http://localhost:8000/render?url=http%3A%2F%2Fwww.google.co.za%2Fimages%2Fsrpr%2Flogo3w.png&width=100
or
http://localhost:8000/render?url=http%3A%2F%2Fwww.google.co.za%2Fimages%2Fsrpr%2Flogo3w.png&height=100
The aspect ratio will be preserved in this case.
The width
or height
values may be set to wurfl
, in which case a WURFL lookup will be performed using the specified ua
argument, or the detected device. Opera Mini's custom user agent header is supported.
If you need to resize the image to specific dimensions, specify BOTH the width and the height:
http://localhost:8000/render?url=http%3A%2F%2Fwww.google.co.za%2Fimages%2Fsrpr%2Flogo3w.png&width=100&height=100
Text can be annotated diagonally across the image by adding "annotation=", e.g.
http://localhost:8000/render?url=http%3A%2F%2Fwww.google.co.za%2Fimages%2Fsrpr%2Flogo3w.png&annotation=SAMPLE
For debugging purposes the following additional arguments have been exposed:
nocache
- Forces the imager to retrieve the specified image from the source and repopulate the cached copy, rather than use the cached copy.debug
- Enables detailed debug logging for the request.
A graphical user interface is available at
http://localhost:8000/ui
Check out
http://www.imagemagick.org/Usage/annotating/
Some notes from the Imagick website relating to geometry specifications...
size | General description (actual behavior can vary for different options and settings) |
---|---|
scale% | Height and width both scaled by specified percentage. |
scale-x%xscale-y% | Height and width individually scaled by specified percentages. (Only one % symbol needed.) |
width | Width given, height automagically selected to preserve aspect ratio. |
xheight | Height given, width automagically selected to preserve aspect ratio. |
widthxheight | Maximum values of height and width given, aspect ratio preserved. |
widthxheight^ | Minimum values of width and height given, aspect ratio preserved. |
widthxheight! | Width and height emphatically given, original aspect ratio ignored. |
widthxheight> | Shrinks an image with dimension(s) larger than the corresponding width and/or height argument(s). |
widthxheight< | Enlarges an image with dimension(s) smaller than the corresponding width and/or height argument(s). |
area@ | Resize image to have specified area in pixels. Aspect ratio is preserved. |