[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] mem_inspect and png

Eric Hodel

8/31/2006 10:47:00 PM

I'm pleased to announce to new libraries written by members of the
Seattle Ruby Brigade, mem_inspect and png!

===

mem_inspect is ObjectSpace.each_object on crack. mem_inspect gives
you the contents of each slot in Ruby's heap. mem_inspect also
includes viewers that let you visualize the contents of Ruby's heap.

To install:

$ sudo gem install mem_inspect

Then you'll need to build a patched ruby:

ruby_mem_inspect_build

You'll then have a ruby capable of running mem_inspect in
mem_inspect_ruby_1_8.

You can make an image with:

mem_inspect_ruby_1_8/ruby_mem_inspect -S ruby_mem_dump

Which will give you a PNG in your current directory named:

mem_inspect.PID.TIMESTAMP.png

You'll get an image that looks something like this:

http://flickr.com/photos/drbrain/...

Bigger:

http://flickr.com/photo_zoom.gne?id=229482312&...

To dump a PDF any time you want:

require 'meminspect/png_viewer'

MemInspect::PNGViewer.new(1024, 768).draw

You can also dump to an AquaTerm plot window if you have RubyCocoa
and AquaTerm installed.

require 'meminspect/aquaterm_viewer'

MemInspect::AquatermViewer.new(1024, 768).draw

===

png is a pure-ruby PNG writing library written by Ryan Davis.

To install:

$ sudo gem install png

To use:

require 'png'

canvas = PNG::Canvas.new 200, 200

# Set a point to a color
canvas[100, 100] = PNG::Color::Black

# draw an anti-aliased line
canvas.line 50, 50, 100, 50, PNG::Color::Blue

png = PNG.new canvas
png.save 'blah.png'

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



7 Answers

James Gray

8/31/2006 10:51:00 PM

0

On Aug 31, 2006, at 5:46 PM, Eric Hodel wrote:

> png is a pure-ruby PNG writing library written by Ryan Davis.
>
> To install:
>
> $ sudo gem install png
>
> To use:
>
> require 'png'
>
> canvas = PNG::Canvas.new 200, 200
>
> # Set a point to a color
> canvas[100, 100] = PNG::Color::Black
>
> # draw an anti-aliased line
> canvas.line 50, 50, 100, 50, PNG::Color::Blue
>
> png = PNG.new canvas
> png.save 'blah.png'

I'm lovin' that. Too cool!

James Edward Gray II


William Crawford

9/1/2006 10:29:00 AM

0

Eric Hodel wrote:
> png is a pure-ruby PNG writing library written by Ryan Davis.
>
> To install:
>
> $ sudo gem install png
>
> To use:
>
> require 'png'
>
> canvas = PNG::Canvas.new 200, 200
>
> # Set a point to a color
> canvas[100, 100] = PNG::Color::Black
>
> # draw an anti-aliased line
> canvas.line 50, 50, 100, 50, PNG::Color::Blue
>
> png = PNG.new canvas
> png.save 'blah.png'
>
> --
> Eric Hodel - drbrain@segment7.net - http://blog.se...
> This implementation is HODEL-HASH-9600 compliant
>
> http://trackmap.rob...

Is there a website for it? Maybe an rDoc page? I'd like to know some
things like 'Does it draw dashed/dotted lines?' etc.

RMagick does, but it has a little glitch where if the last dash on a
line isn't whole, it doesn't draw it. (At least in my playing with it
so far.) I think I can work around it, but if I can find a library that
works better, I'll use that instead.

If you're wondering why it matters so much, I'm making a very very very
simple little plaid design creator in ruby. The dashed lines are used
to simulate the weaving of the threads. The upper and left edges are
smooth, but the right and bottom edges aren't, because of this bug. I
think I can simply draw over the edge of the canvas and fix it, but I
haven't gotten around to trying yet. Being able to simply draw it
correctly without hacks would be much better.

I could, of course, draw it pixel by pixel, but I think that'd be quite
a bit slower.

--
Posted via http://www.ruby-....

Eric Hodel

9/2/2006 1:40:00 AM

0

On Sep 1, 2006, at 3:28 AM, William Crawford wrote:

> Eric Hodel wrote:
>> png is a pure-ruby PNG writing library written by Ryan Davis.
>
> Is there a website for it? Maybe an rDoc page? I'd like to know some
> things like 'Does it draw dashed/dotted lines?' etc.

Not yet. Its really small so:

$ sudo gem install png
$ ri -l | grep PNG
[...]
PNG::Canvas#line
[...]
$ ri PNG::Canvas#line
------------------------------------------------------- PNG::Canvas#line
line(x0, y0, x1, y1, color)
------------------------------------------------------------------------
Draws a line using Xiaolin Wu's antialiasing technique.

http://en.wikipedia.org/wiki/Xiaolin_Wu's_line...
(In short, no.)

> If you're wondering why it matters so much, I'm making a very very
> very
> simple little plaid design creator in ruby. The dashed lines are used
> to simulate the weaving of the threads. The upper and left edges are
> smooth, but the right and bottom edges aren't, because of this bug. I
> think I can simply draw over the edge of the canvas and fix it, but I
> haven't gotten around to trying yet. Being able to simply draw it
> correctly without hacks would be much better.
>
> I could, of course, draw it pixel by pixel, but I think that'd be
> quite
> a bit slower.

PNG draws pixel by pixel.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Ryan Williams

9/2/2006 7:57:00 AM

0

On 9/1/06, William Crawford <wccrawford@gmail.com> wrote:
> Eric Hodel wrote:
> > png is a pure-ruby PNG writing library written by Ryan Davis.
> >
> > To install:
> >
> > $ sudo gem install png
> >
> > To use:
> >
> > require 'png'
> >
> > canvas = PNG::Canvas.new 200, 200
> >
> > # Set a point to a color
> > canvas[100, 100] = PNG::Color::Black
> >
> > # draw an anti-aliased line
> > canvas.line 50, 50, 100, 50, PNG::Color::Blue
> >
> > png = PNG.new canvas
> > png.save 'blah.png'
> >
> > --
> > Eric Hodel - drbrain@segment7.net - http://blog.se...
> > This implementation is HODEL-HASH-9600 compliant
> >
> > http://trackmap.rob...
>
> Is there a website for it? Maybe an rDoc page? I'd like to know some
> things like 'Does it draw dashed/dotted lines?' etc.
>
> RMagick does, but it has a little glitch where if the last dash on a
> line isn't whole, it doesn't draw it. (At least in my playing with it
> so far.) I think I can work around it, but if I can find a library that
> works better, I'll use that instead.
>
> If you're wondering why it matters so much, I'm making a very very very
> simple little plaid design creator in ruby. The dashed lines are used
> to simulate the weaving of the threads. The upper and left edges are
> smooth, but the right and bottom edges aren't, because of this bug. I
> think I can simply draw over the edge of the canvas and fix it, but I
> haven't gotten around to trying yet. Being able to simply draw it
> correctly without hacks would be much better.

I think that drawing over the edge would be simplest -- you can set
the clip so you don't have to fix it later:
http://www.imagemagick.org/RMagick/doc/draw.html...

If you're using RVG, there's the same thing:
http://www.imagemagick.org/RMagick/doc/rv...

But anyway, cool work with the PNG library!

-RYaN

>
> I could, of course, draw it pixel by pixel, but I think that'd be quite
> a bit slower.
>
> --
> Posted via http://www.ruby-....
>
>

William Crawford

9/2/2006 11:23:00 AM

0

Ryan Williams wrote:
> I think that drawing over the edge would be simplest -- you can set
> the clip so you don't have to fix it later:
> http://www.imagemagick.org/RMagick/doc/draw.html...
> -RYaN

Thanks, I figured out I could tell it to draw over the edge and it'd
work fine.

But then I came to another problem with rmagick. If you tell it to draw
the dashed line with 2 on and 2 off, it draws 3 on and 1 off. I think
it has something to do with aliasing or something. It's a pain, anyhow.
So I'm probably going to try drawing each pixel individually, or
switching this new PNG library and see if that draws what I need.
(Pixel by pixel.)

--
Posted via http://www.ruby-....

Harold Hausman

9/3/2006 2:13:00 AM

0

On 9/1/06, Eric Hodel <drbrain@segment7.net> wrote:
> I'm pleased to announce to new libraries written by members of the
> Seattle Ruby Brigade, mem_inspect and png!
>
> png is a pure-ruby PNG writing library written by Ryan Davis.
>

File.open on windows needs to be explicitly told to be binary. Adding
the magic 'b' here got me going on win32:

##
# Writes the PNG to +path+.

def save(path)
# Hooray, magic 'b' !
File.open(path, "wb") do |f|
...
end
end

#Thanks for this cool lib
-Harold

Eric Hodel

9/3/2006 4:28:00 AM

0

On Sep 2, 2006, at 7:13 PM, Harold Hausman wrote:

> On 9/1/06, Eric Hodel <drbrain@segment7.net> wrote:
>> I'm pleased to announce to new libraries written by members of the
>> Seattle Ruby Brigade, mem_inspect and png!
>>
>> png is a pure-ruby PNG writing library written by Ryan Davis.
>>
>
> File.open on windows needs to be explicitly told to be binary. Adding
> the magic 'b' here got me going on win32:

Yes, I've fixed this in the source repository.

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...