Question

I'm running a Rails 3.2 app locally using MiniMagick with ImageMagick and this piece of code

img.combine_options do |c| 
    c.gravity 'Center'
    c.font "#{::Rails.root}/public/fonts/Impact.ttf" 
    c.pointsize '125'
    c.kerning '-6'
    c.draw "text 0,-120 '#{self.line1}'"
    c.draw "text 0,-16 '#{self.line2}'"
    c.draw "text 0,88 '#{self.line3}'"
    c.fill "#ffffff"
end

Which works fine locally, the text is written on top of the image as expected and comes out white.

Once I deploy this to Heroku (Cedar), I get no errors but the text is written on top of the image in black.

This is the first time I've used MiniMagick and ImageMagick together on Heroku so, maybe I'm missing something with color depth? Is it that the image is PNG?

Was it helpful?

Solution

After properly reading the command line options available to MiniMagick via ImageMagick for the 'draw' option I found this paragraph that solved the issue:

Options are processed in command line order so be sure to use these options before the -draw option.

So by changing the order the options are passed in, to move the fill color to above the 'draw' param solved it, as below:

img.combine_options do |c| 
  c.gravity 'Center'
  c.font "#{::Rails.root}/public/fonts/Impact.ttf"
  c.fill "#ffffff"
  c.pointsize '125'
  c.kerning '-6'
  c.draw "text 0,-120 '#{self.line1}'"
  c.draw "text 0,-16 '#{self.line2}'" 
  c.draw "text 0,88 '#{self.line3}'"
end

Problem solved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top