# Mem\_inspect and png

**URL:** <https://www.ruby-forum.com/t/mem-inspect-and-png/67140>\
**Category:** Ruby\
**Created:** [September 1, 2006, 12:49am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140 "2006-09-01T00:49:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 1, 2006, 12:49am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/1 "2006-09-01T00:49:23Z")

</div>

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:

[Memory Map | BLACK: unknown (char \*, VALUE \*, struct st\_tabl… | Flickr](http://flickr.com/photos/drbrain/229482312/)

Bigger:

[All sizes | Memory Map | Flickr - Photo Sharing!](http://flickr.com/photo_zoom.gne?id=229482312&size=o)

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 D…

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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 1, 2006, 12:53am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/2 "2006-09-01T00:53:24Z")

</div>

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

> 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 G. II

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 1, 2006, 12:28pm UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/3 "2006-09-01T12:28:26Z")

</div>

Eric H. wrote:

> png is a pure-ruby PNG writing library written by Ryan D…
> 
> 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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

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.

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 2, 2006, 10:00am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/4 "2006-09-02T10:00:03Z")

</div>

On 9/1/06, William C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> 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#clip\_path](http://www.imagemagick.org/RMagick/doc/draw.html#clip_path)

If you’re using RVG, there’s the same thing:  
[http://www.imagemagick.org/RMagick/doc/rvgclip.html](http://www.imagemagick.org/RMagick/doc/rvgclip.html)

But anyway, cool work with the PNG library!

-RYaN

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 2, 2006, 1:19pm UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/5 "2006-09-02T13:19:49Z")

</div>

Ryan W. 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#clip\_path](http://www.imagemagick.org/RMagick/doc/draw.html#clip_path)  
> -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.)

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 2, 2006, 3:41am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/6 "2006-09-02T03:41:57Z")

</div>

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

> Eric H. wrote:
> 
> > png is a pure-ruby PNG writing library written by Ryan D…
> 
> 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_algorithm\

```

(In short, no.)

> quite  
> a bit slower.

PNG draws pixel by pixel.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 4, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/7 "2006-09-04T14:43:26Z")

</div>

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

> On 9/1/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 D…
> 
> 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 H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![miracleofmagick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/71c47a/32.png) [@miracleofmagick](https://www.ruby-forum.com/u/miracleofmagick)\
**Post date:** [September 3, 2006, 4:13am UTC](https://www.ruby-forum.com/t/mem-inspect-and-png/67140/8 "2006-09-03T04:13:38Z")

</div>

On 9/1/06, Eric H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 D…

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
