# Rmagick crash?

**URL:** https://rubytalk.org/t/rmagick-crash/13308
**Category:** ruby-talk
**Created:** [29 August 2004 11:26 UTC](https://rubytalk.org/t/rmagick-crash/13308 "2004-08-29T11:26:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Roeland\_Moors](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@Roeland\_Moors](https://rubytalk.org/u/Roeland_Moors)
#### Post date: [29 August 2004 11:26 UTC](https://rubytalk.org/t/rmagick-crash/13308/1 "2004-08-29T11:26:07Z")

</div>

I use rmagick to transform an image.  
This works nice for 1 or a couple or images, but when I do more  
images I have problems.

After a couple of images my program just stops with the output  
'killed'. No error message, nothing.

Then I updated to the latest version of rmagick en tried again.  
It did more images, but then my pc completely crashed!  
(I'm not using windows 🙂

What could cause these problems?  
Am I doing something stupid?

Here are pieces of the code:

# convert a lot of pictures  
@photolist.each do |photo|  
&nbsp;&nbsp;&nbsp;&nbsp;photo.convert()  
end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
class Photo  
&nbsp;&nbsp;&nbsp;&nbsp;def convert(preview = false)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img = Magick::ImageList.new(@name)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width = $format['width']  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = $format['height']  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;top = $format['border\_top']  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;left = $format['border\_left']

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if preview  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;top = top / (height/200)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;left = left / (width/300)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width = 300  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = 200  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# rotate to landscape  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.rotate!(90) if img.rows \> img.columns

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;geometry = "#{width}x#{height}"

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# resize current image  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.change\_geometry!(geometry) do |cols, rows|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if preview  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.scale!(cols, rows)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#img.thumbnail!(cols, rows)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;img.resize!(cols, rows)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# create an empty image  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest = Magick::ImageList.new  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest.new\_image(width + 2\*left, height + 2\*top) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.background\_color = 'black'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# create text on photo  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text = Magick::Draw.new  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.gravity = Magick::NorthWestGravity  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.rotation = 90

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# date  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps = 2.5 \* width /100  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.pointsize = ps  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos = width+left-ps  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.annotate(dest, ps, height, pos, top, @date) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.fill = 'white'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ps = 6 \* width /100  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.pointsize = ps  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pos = pos-ps  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text.annotate(dest, ps, height, pos, top, @description) do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.fill = 'white'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# merge images  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest = dest.composite(img, left, top, Magick::InCompositeOp)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest.write($filename)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$filename  
&nbsp;&nbsp;&nbsp;&nbsp;end

end

> **···**
>
> --  
> Roeland

---

<div class="post-metadata">

### Author: ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)
#### Post date: [29 August 2004 15:45 UTC](https://rubytalk.org/t/rmagick-crash/13308/2 "2004-08-29T15:45:28Z")

</div>

Roeland Moors wrote:

> I use rmagick to transform an image.  
> This works nice for 1 or a couple or images, but when I do more  
> images I have problems.
> 
> After a couple of images my program just stops with the output  
> 'killed'. No error message, nothing.
> 
> Then I updated to the latest version of rmagick en tried again.  
> It did more images, but then my pc completely crashed!  
> (I'm not using windows 🙂
> 
> What could cause these problems?  
> Am I doing something stupid?

Sorry you're having trouble with RMagick.

I'm guessing that you're running out of memory. For some reason GC is not  
able to clean up the image objects you're no longer using.

If you send me the whole program I'll see what I can do.

---

<div class="post-metadata">

### Author: ![Roeland\_Moors](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@Roeland\_Moors](https://rubytalk.org/u/Roeland_Moors)
#### Post date: [30 August 2004 08:22 UTC](https://rubytalk.org/t/rmagick-crash/13308/3 "2004-08-30T08:22:28Z")

</div>

You can get it from CVS here:  
[http://rubyforge.org/projects/photoprep/](http://rubyforge.org/projects/photoprep/)

After installing it, you can start it with 'photoprep \*.jpg' or  
somthing like that.  
The program is not finished so I hope you can start it 🙂

Thanks

Roeland

> **···**
>
> On Mon, Aug 30, 2004 at 12:45:28AM +0900, Tim Hunter wrote:
> 
> > Roeland Moors wrote:
> > 
> > \> I use rmagick to transform an image.  
> > \> This works nice for 1 or a couple or images, but when I do more  
> > \> images I have problems.  
> > \>  
> > \> After a couple of images my program just stops with the output  
> > \> 'killed'. No error message, nothing.  
> > \>  
> > \> Then I updated to the latest version of rmagick en tried again.  
> > \> It did more images, but then my pc completely crashed!  
> > \> (I'm not using windows 🙂  
> > \>  
> > \> What could cause these problems?  
> > \> Am I doing something stupid?  
> > \>
> > 
> > Sorry you're having trouble with RMagick.
> > 
> > I'm guessing that you're running out of memory. For some reason GC is not  
> > able to clean up the image objects you're no longer using.
> > 
> > If you send me the whole program I'll see what I can do.
