FlexImage pre-processing avec beer in brazil

Hi everyone…

Since i can’t find noob friendly information about rmagick and
fleximage on the web, I’m here offering a beer for the one good soul
who can help me to get rid of my ignorance.

I’ve been trying for weeks to make fleximage to work, and now that it
does, I’d like to do the following:

class MyImage < FlexImage::Model
def fooify!
img = rmagick_image

# retrieve image's width and height

# compare both values to determine if the image is "portrait" or

“landscap” (if width > height, aspect_ratio = landscape, etc…)

# if image is "portrait", resizes it using a threshold of 200px

height, decreasing the width proportionally.
# else, if it’s landscape, it resizes to a 400px WIDTH, resizing
the height proportionally

# than store the image in a blob or filesystem, and the

aspect_ratio value in the DB

self.rmagick_image = img


My main point of ignorance is about how to gather information about
the image’s width and height.

The rest I think I can figure out myself (but since I took a lot of
time just to make fleximage work, I’m not so confident and I still
apreciate your kindness to share your thoughts on it, specially if you
think that creating a method inside the model isn’t the best aproach
and have better practices in mind)

I would really apreciate some help on this, and if you can do it, I
owe you a couple beers (however, you’ll have to come to brazil to
drink it)

Thank You

On Mar 24, 4:02 am, Daniel D. [email protected] wrote:

Hi everyone…


height, decreasing the width proportionally.

My main point of ignorance is about how to gather information about
the image’s width and height.

width = img.columns
height = img.rows
aspect = height > 0 ? width.to_f / height.to_f : 0

aspect_string = aspect > 1 ? ‘landscape’ : ‘portrait’

For resizing, you’ll probably need to calculate the percentage of
scale to meet your desired dimensions, and then use the scale! method.

scale_pct = aspect > 1 ? 400.0 / width.to_f : 200.0 / height.to_f

Full documentation on rMagick is here:


The primary thing you’ll want to look at in the documentation is in
the reference section, under Classes, the four pages about the Image
class. There are also some useful tutorials.

Jim Crate
Que Viva, LLC

I couldn’t try your code yet, but I’ll do it within the next couple

But thank you very much for the help! I’m sure this will be very
helpful to me and a lot of people.

The code you’ve written is beautiful. It worked like a charm. Thank
you again!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs