RMagick Thumbnailing Question

  • Thread starter Raymond Brigleb
  • Start date
R

Raymond Brigleb

Hello: this is my first post, so a brief introduction. My name is
Ray, I live in Portland, I'm a fresh (circa 2005) Ruby convert, and I
work with needmoredesigns.com. Hello!

I'm writing an application (in Rails) that uses much of RMagick's...
magic. Thumbnails are a big part of the job, but I'm having
difficulty getting my head around the Geometry (?) class... in a
sense, what I'm trying to do is create thumbnails that "fill the
space" rather than are "restricted to the space" they're in. Meaning,
if I say I want 100x100 thumbnails, I want it to first resize, then
actually crop a 300x100 image to the middle 100 pixels. Make any
sense? I just think they'll look better that way.

My question is, has anybody done this? I've seen it in Backpack
(backpackhq.com) which I'm just guessing uses this library. I'm
wondering if anybody has any helpful tips or perhaps some code they
could share with me.

Thanks and well met,
Raymond
 
J

Joe Van Dyk

On 9/8/05 said:
I'm writing an application (in Rails) that uses much of RMagick's...
magic. Thumbnails are a big part of the job, but I'm having
difficulty getting my head around the Geometry (?) class... in a
sense, what I'm trying to do is create thumbnails that "fill the
space" rather than are "restricted to the space" they're in. Meaning,
if I say I want 100x100 thumbnails, I want it to first resize, then
actually crop a 300x100 image to the middle 100 pixels. Make any
sense? I just think they'll look better that way.
=20
My question is, has anybody done this? I've seen it in Backpack
(backpackhq.com) which I'm just guessing uses this library. I'm
wondering if anybody has any helpful tips or perhaps some code they
could share with me.

http://studio.imagemagick.org/RMagick/doc/struct.html#Geometry

Check out the flags at the bottom. In particular, the '!' flag.

What you probably want is 100!x100! or something similar.
 
R

rmagick

Sounds to me like you need a 2-step method, assuming the original
images are not already 300x100.

Use the change_geometry method to compute the new dimensions for your
thumbnail. If you want to make sure that your thumbnail is always 100
pixels high, specify a geometry string argument with just your target
height, like this: "x100". If you want your thumbnail to be always 300
pixels wide, just specify the target width: "300". The change_geometry
method will compute new dimensions you can use as arguments to the
resize method. If the result still doesn't have the right shape you can
use the crop method to crop the resized image to the shape you want. If
you want the middle 100x100 part of the image you can use something
like:

img.crop!(Magick::CenterGravity, 100, 100)
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top