[ANN] SmartImage 0.0.2: a sane cross-platform image compositing andthumbnail library

T

Tony Arcieri

SmartImage is a new, powerful, cross-platform Ruby library for
compositing images and making thumbnails:

gem install smartimage

The above command should work on MRI (or any other platform that can
load the RMagick C extension) as well as JRuby.

----
Background
----

http://github.com/tarcieri/smartimage
http://rubygems.org/gems/smartimage

Once upon a time there was RMagick.=A0 It was powerful but it was large
and confusing.=A0 Wading through a sea of documentation to figure out
how to do something simple like create a thumbnail was a monumental
undertaking!=A0 It was also much maligned for leaking memory, due to its
API providing low level access to the C library, which included manual
memory management.

Then along came ImageScience.=A0 It made thumbnails and it was simple
and it was good!=A0 But it was only designed for the standard Matz Ruby
Interpreter.=A0 Then along came JRuby, and JRuby couldn't run
ImageScience.=A0 The JRuby people conjured up ImageVoodoo to fill in for
ImageScience, but even then, it wasn't seamless.=A0 And making
thumbnails was *all* that ImageScience and ImageVoodoo could do!
ImageVoodoo added more, but it wasn't present in the ImageScience API.

I've often felt myself wishing that there was an alternative between
these two that incorporates more powerful image processing features
without drowning you in a sea
of APIs.=A0 I also work on both MRI and JRuby and prefer libraries that
work seamlessly
across both platforms.=A0 And thus SmartImage was born.

----
Can it create thumbnails for my Ruby on Rails-based web application?
----

Yes, SmartImage *CAN* create thumbnails for your Ruby on Rails-based
web application! And it can do it in the most cross-platform manner
imaginable! If you are looking for a thumbnail solution that will
allow you to safely migrate your web application to JRuby in the
future, look no further than SmartImage.

To use SmartImage in your Rails application, simply add the following
to config/environment.rb:

config.gem 'smartimage'

(there is an appropriate place to put this line, BTW. The exact
location is left as an exercise to the reader)

That's it! Now wherever you would like to generate thumbnails, use
the following:

SmartImage.thumbnail_file(
"path/to/input.jpg",
"path/to/output.jpg",
:width =3D> 69,
:height =3D> 42
)

This will generate a thumbnail which is at most 69 pixels wide (but
could be smaller) and at most 42 pixels tall (but again, could be
smaller). It looks at the file extension to determine the output
format. We specified a .jpg so it will output a JPEG encoded image.

Why could it be smaller, you ask? Because SmartImage preserves the
aspect ratio of the original image by default. SmartImage allows you
to set aside space of a predetermined width/height, but will ensure
images are scaled with their aspect ratio preserved.

Don't like this behavior? Want to stretch out your thumbnails all
weird? Just turn it off:

SmartImage.thumbnail_file(
"path/to/input.jpg",
"path/to/output.jpg",
:width =3D> 69,
:height =3D> 42,
:preserve_aspect_ratio =3D> false
)

Tada! Stretched-out images! Yay!

----
What if I want to work with raw image data instead of files?
----

SmartImage provides both file-based and data-based methods for every
API. All the APIs are the same, except file-based APIs have "_file"
on the end.

For example, above we used the SmartImage.thumbnail_file API.
However, there's also a SmartImage.thumbnail API that works on raw
image data:

thumbnail =3D SmartImage.thumbnail image, :width =3D> 69,
:height =3D> 42,
:format =3D> :jpg

This API produces a thumbnail in-memory from the given input image,
also in-memory. We've requested a .jpg thumbnail, with a max width of
69 and a max height of 42.

If an image format isn't specified, the default is PNG.

----
What backends are supported?
----

SmartImage works by implementing a platform-specific SmartImage::Canvas cla=
ss
that encompasses all of the low level image manipulation primitives. Two s=
uch
canvases are currently available:

* SmartImage::RMagickCanvas: a canvas backend based on the RMagick gem
* SmartImage::JavaCanvas: a canvas backend based on Java AWT/Graphics2D API=
s

----
What else can it do?
---

SmartImage is a full-blown image compositing library which can
automate tasks similar to Photoshop macros, such as assembling and
compositing layers and alpha masks. For more information on these
features, please see the README:

http://github.com/tarcieri/SmartImage/blob/master/README.markdown

----
Mailing List, Author Info
----

You can subscribe to the SmartImage mailing list by sending email to:

(e-mail address removed)

SmartImage was created by Tony Arcieri. You can contact him through
github or follow him on Twitter at @bascule. He also frequents IRC on
freenode as tarcieri.
 
P

Peter Hickman

[Note: parts of this message were removed to make it a legal post.]

Interesting. Does it correctly orient images? There is a flag in the EXIF
data that tells you which orientation the picture was taken in. So if you
turn your camera from landscape to portrait the flag is set. This was the
thumbnail would be the right way up (even if the image file was not).
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

On Tue, Mar 30, 2010 at 9:08 AM, Peter Hickman <
Interesting. Does it correctly orient images? There is a flag in the EXIF
data that tells you which orientation the picture was taken in. So if you
turn your camera from landscape to portrait the flag is set. This was the
thumbnail would be the right way up (even if the image file was not).

Offhand I can't say... I'd need to write a spec for it.

I would like to provide consistent semantics across all of the backend
canvas libraries (RMagick and Java AWT/Graphics2D for the time being) and
that's something worth checking out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top