Search code examples
ruby-on-rails-4carrierwaveminimagick

Adding text to an image with Carrierwave and mini_magick


I'm trying to put text on an image via carrierwave and mini_magic. The code runs without erros, but the resulting image has no text on it.

version :text do
   process :put_text_stamp
end

def put_text_stamp
  manipulate! do |img|
    img.combine_options do |c|
      c.gravity 'Center'
      c.fill 'red'
      c.pointsize '22'
      c.draw "text 0,0 'TEXT'"
    end
    img = yield(img) if block_given?
    img
  end
end

Solution

  • Hi just this morning I encountered the same problem, I'm still on rails 3.2 but this one worked fine for me. I guess its something with your yield function.

      process :resize_to_limit => [800, 800]
      process :add_text
    
      def add_text
        manipulate! do |image|
          image.combine_options do |c|
            c.gravity 'Center'
            c.pointsize '22'
            c.draw "text 0,0 'test'"
            c.fill 'white'
          end
          image
        end    
      end