R
Roeland Moors
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|
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:
raw.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
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|
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:
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