[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RMagick question

Joe Van Dyk

4/7/2005 1:07:00 AM

Hi,

I'd like to generate a thumbnail of an image. The thumbnail should
have curved corners (corners colored a specified color). Any ideas on
what functions I could use?

Thanks,
Joe


17 Answers

Tim Hunter

4/7/2005 1:28:00 AM

0

Joe Van Dyk wrote:
> Hi,
>
> I'd like to generate a thumbnail of an image. The thumbnail should
> have curved corners (corners colored a specified color). Any ideas on
> what functions I could use?
>
> Thanks,
> Joe
>
>
You might try this approach. Start by making a thumbnail from your image
with #resize or #thumbnail. Use Image.new to construct a second image
the same size as the thumbnail. Specify the color you want as the
background color. Use #roundrectangle in the Draw class to draw a
rounded rectangle on the image. Specify the stroke and fill colors as
"none" or "transparent". Use #composite with the Magick::OverCompositeOp
argument to composite this image over the thumbnail.

Give me a shout if you want and I'll see if I can put together an
example that does this.

If you want the corners to be transparent instead of some specific
color, check out the vignette example in the examples/ subdirectory or
the "Add transparency with a mask" example in the RMagick portfolio at
http://rmagick.rub....

Tim Hunter

4/7/2005 11:40:00 PM

0

Joe Van Dyk wrote:
> Hi,
>
> I'd like to generate a thumbnail of an image. The thumbnail should
> have curved corners (corners colored a specified color). Any ideas on
> what functions I could use?
>
> Thanks,
> Joe
>
>
Here's a script that adds transparent round corners.

require 'RMagick'
include Magick

hat = Image.read('Flower_Hat.jpg').first
hat.resize!(0.5)

mask = Image.new(hat.columns, hat.rows) {self.background_color = 'black'}
gc = Draw.new
gc.stroke('white').fill('white')
gc.roundrectangle(0, 0, hat.columns-1, hat.rows-1, 20, 20)
gc.draw(mask)

mask.matte = false
hat.matte = true

thumb = hat.composite(mask, CenterGravity, CopyOpacityCompositeOp)
thumb.display

Stephen Birch

4/8/2005 9:57:00 AM

0

Timothy Hunter(cyclists@nc.rr.com)@2005-04-08 08:44:
> require 'RMagick'
> include Magick

Newbie Q ... why does RMagick need a require *and* an include
statement, I don't that in other packages?

Steve


Tim Hunter

4/8/2005 11:44:00 AM

0

Stephen Birch wrote:
> Timothy Hunter(cyclists@nc.rr.com)@2005-04-08 08:44:
>
>>require 'RMagick'
>>include Magick
>
>
> Newbie Q ... why does RMagick need a require *and* an include
> statement, I don't that in other packages?
>
> Steve
>
>
The include statement isn't necessary, it's just that I'm a lazy typer.

All the RMagick classes - Image, Draw, etc. - are enclosed in the Magick
module. Without the include statement, you would refer to them as
Magick::Image, Magick::Draw, etc. The include statement mixes the Magick
module into Object, which adds the Magick constants to Object.
Thereafter you can refer to these classes without the Magick prefix.

Including Magick in Object in the general case is a bad idea because it
could cause namespace conflicts, but for the purposes of an example it's
okay and saves a few keystrokes.

Martin DeMello

4/8/2005 12:08:00 PM

0

Stephen Birch <sgbirch@imsmail.org> wrote:
> Timothy Hunter(cyclists@nc.rr.com)@2005-04-08 08:44:
> > require 'RMagick'
> > include Magick
>
> Newbie Q ... why does RMagick need a require *and* an include
> statement, I don't that in other packages?

This mixes in the Magick module, so that you don't need to preface its
module methods with Magick::

Compare the following:

$ irb
irb(main):001:0> sin(PI)
NameError: uninitialized constant PI
from (irb):1
irb(main):002:0> Math::sin(Math::PI)
=> 1.22464679914735e-16
irb(main):003:0> include Math
=> Object
irb(main):004:0> sin(PI)
=> 1.22464679914735e-16

martin

Glenn Parker

4/8/2005 12:44:00 PM

0

Stephen Birch wrote:
>
> Newbie Q ... why does RMagick need a require *and* an include
> statement, I don't that in other packages?

Check out the recommended usage for the Benchmark module.

--
Glenn Parker | glenn.parker-AT-comcast.net | <http://www.tetrafoi...


Stephen Birch

4/8/2005 1:26:00 PM

0

Timothy Hunter(cyclists@nc.rr.com)@2005-04-08 21:34:
> The include statement isn't necessary, it's just that I'm a lazy typer.

Got it ... thanks

Steve


Joe Van Dyk

4/11/2005 9:59:00 PM

0

Thanks for all the responses (check out www.jerrymahan.com for the result).

Another RMagick question:

I'm trying to get the width and height (in pixels) of an image. I've
searched the docs and the closest I can find to what I want is the
geometry string. But the string is something like
"<width>34</width><height>88</height>" or something weird like that.
Isn't there an easier way to get the width/height of an image?

Thanks,
Joe

On Apr 6, 2005 6:06 PM, Joe Van Dyk <joevandyk@gmail.com> wrote:
> Hi,
>
> I'd like to generate a thumbnail of an image. The thumbnail should
> have curved corners (corners colored a specified color). Any ideas on
> what functions I could use?
>
> Thanks,
> Joe
>


Tim Hunter

4/11/2005 10:05:00 PM

0

Joe Van Dyk wrote:
> Thanks for all the responses (check out www.jerrymahan.com for the result).
>
> Another RMagick question:
>
> I'm trying to get the width and height (in pixels) of an image. I've
> searched the docs and the closest I can find to what I want is the
> geometry string. But the string is something like
> "<width>34</width><height>88</height>" or something weird like that.
> Isn't there an easier way to get the width/height of an image?

Sure. Use the #columns and #rows attributes of the image.

See http://www.simplesystems.org/RMagick/doc/comtasks... for an
example.

wannes

4/11/2005 10:23:00 PM

0

Joe Van Dyk wrote:
> Another RMagick question:
> I'm trying to get the width and height (in pixels) of an image. I've
> searched the docs and the closest I can find to what I want is the
> geometry string. But the string is something like
> "<width>34</width><height>88</height>" or something weird like that.
> Isn't there an easier way to get the width/height of an image?

http://studio.imagemagick.org/RMagick/doc/imageattrs...
http://studio.imagemagick.org/RMagick/doc/imageattrs.ht...

didn't test it, but seems logical.

grtz,
wannes