File_column, RMagick, and watermarking


#1

I’m working on a photo gallery and I’m using File_column to handle the
uploads of the files and create my thumbnails, but does anyone here have
any idea how to have a watermark (opaque text maybe) placed over one of
the versions? Any ideas on how to go about this would be great. Even if
it’s just straight RMagick code, that would be fine too.

Thanks in advance for the help!

Brian H.
Web D.
Learning & Technology Services
Schofield 3-B
University of Wisconsin-Eau Claire
715 836 3585
removed_email_address@domain.invalid


#2

I have a similar requirement; did you find any solution for this?

thanks

Hogan, Brian P. wrote:

I’m working on a photo gallery and I’m using File_column to handle the
uploads of the files and create my thumbnails, but does anyone here have
any idea how to have a watermark (opaque text maybe) placed over one of
the versions? Any ideas on how to go about this would be great. Even if
it’s just straight RMagick code, that would be fine too.

Thanks in advance for the help!

Brian H.
Web D.
Learning & Technology Services
Schofield 3-B
University of Wisconsin-Eau Claire
715 836 3585
removed_email_address@domain.invalid


#3

Hogan, Brian P. wrote:

I’m working on a photo gallery and I’m using File_column to handle the
uploads of the files and create my thumbnails, but does anyone here have
any idea how to have a watermark (opaque text maybe) placed over one of
the versions? Any ideas on how to go about this would be great. Even if
it’s just straight RMagick code, that would be fine too.

Thanks in advance for the help!

There are many ways to write text on an image with RMagick. The simplest
way is to use the Draw#text method:
http://www.simplesystems.org/RMagick/doc/draw.html#text. Also check out
the example for the Image#watermark method:
http://www.simplesystems.org/RMagick/doc/image3.html#watermark and the
example for the Image#mask attribute:
http://www.simplesystems.org/RMagick/doc/imageattrs.html#mask. These
last two require that you have RMagick 1.14.0 or later.


#4

FlexImage seems great, but i would prefer to story my images on disk
rather than in the DB… thats not possible with FlexImage, is it?


#5

Hogan, Brian P. wrote:

I’m working on a photo gallery and I’m using File_column to handle the
uploads of the files and create my thumbnails, but does anyone here have
any idea how to have a watermark (opaque text maybe) placed over one of
the versions? Any ideas on how to go about this would be great. Even if
it’s just straight RMagick code, that would be fine too.

Thanks in advance for the help!

Brian H.
Web D.
Learning & Technology Services
Schofield 3-B
University of Wisconsin-Eau Claire
715 836 3585
removed_email_address@domain.invalid

I’ve just released an updated to the FlexImage that makes it super easy
to do just that. Simply provide a PNG and give it some basic info on
how to size and place it.

Check it out.
http://beautifulpixel.com/articles/2006/10/26/flex-image-now-has-special-effects


#6

Thorsten L wrote:

FlexImage seems great, but i would prefer to story my images on disk
rather than in the DB… thats not possible with FlexImage, is it?

Not currently, sorry :frowning:

At the very least you can take a look into the source and see the
rmagick commands that do the overlay. Check out
FlexImage::Model#overlay! for the implementation.


#7

I totally forgot I posted this. I figured it out with RMagick a long
time
ago… it’s pretty simple actually

This places “sample” diagonally across the middle of the image. You
needa
graphic called ‘sample.png’ that contains some alpha transparency but
that’s
easy to create.

class Photo < ActiveRecord::Base

file_column :filename, :magick => {
  :versions => { "thumb" => "50x50", "large" => "320x240>" }
  }

validates_presence_of :filename, :description
before_create :watermark_image

private
def watermark_image
    require 'RMagick'  # probably don't need this line but it's here

anyway
dst = Magick::Image.read(self.filename).first
src =
Magick::Image.read("#{RAILS_ROOT}/config/sample.png").first
result = dst.composite(src, Magick::CenterGravity,
Magick::OverCompositeOp)
result.write(self.filename)

end

end