Rmagick crash?

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 :slight_smile:

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|
    photo.convert()
end
                    
class Photo
    def convert(preview = false)
        img = Magick::ImageList.new(@name)

        width = $format['width']
        height = $format['height']
        top = $format['border_top']
        left = $format['border_left']

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

        # rotate to landscape
        img.rotate!(90) if img.rows > img.columns

        geometry = "#{width}x#{height}"

        # resize current image
        img.change_geometry!(geometry) do |cols, rows|
            if preview
                img.scale!(cols, rows)
                #img.thumbnail!(cols, rows)
            else
                img.resize!(cols, rows)
            end
        end

        # create an empty image
        dest = Magick::ImageList.new
        dest.new_image(width + 2*left, height + 2*top) do
            self.background_color = 'black'
        end

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

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

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

        dest.write($filename)
        $filename
    end

end

···

--
Roeland

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 :slight_smile:

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.

You can get it from CVS here:
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 :slight_smile:

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 :slight_smile:
>
> 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.