Can't get gravity to work with RMagick and 'caption'
- by mph
I'm using RMagick 2.12.2 with ImageMagick 6.5.6-10 on Snow Leopard. I'm trying to put captions on a collection of photos, and I'm getting the caption to work (i.e. it appears on the image), but I can't get the gravity parameter to work correctly.
No matter what I set it to, I end up with some variation on NorthGravity.
For instance: Setting it to SouthWestGravity gives me NorthWestGravity. Setting it to SouthEastGravity gives me NorthEastGravity. Setting it to CenterGravity gives me NorthGravity.
In other words, I can't get the caption to come down off the top of the image.
I'd consider using "annotate," but I need "caption" so the lengthy caption text for each image will wrap.
What am I doing wrong?
Here's the code:
#!/usr/bin/env ruby
require "rubygems"
require "yaml"
require "RMagick"
include Magick
base_dir = "/Users/mike/Desktop/caption_test"
photo_log = File.open("#{base_dir}/photo_log.yaml" )
YAML::load_documents(photo_log) do |doc|
caption = doc["photo-caption"]
filename = doc["file"]
canvas = ImageList.new.from_blob(open("#{base_dir}/#{filename}") { |f| f.read } )
canvas << Magick::Image.read("caption:#{caption}") {
self.gravity = SouthWestGravity
self.size = "#{canvas.first.columns}"
self.font = "Helvetica Neue"
self.pointsize = 12
self.background_color = "#fff"
}.first
canvas.flatten_images.write("#{base_dir}/images/#{filename}")
end