Forum: Ruby on Rails File_column, RMagick, and watermarking

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Hogan, Brian P. (Guest)
on 2006-02-28 21:57
(Received via mailing list)
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
Ruby B. (Guest)
on 2006-10-26 10:51
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
Tim H. (Guest)
on 2006-10-26 23:36
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.ht... and the
example for the Image#mask attribute:
http://www.simplesystems.org/RMagick/doc/imageattr.... These
last two require that you have RMagick 1.14.0 or later.
Alex W. (Guest)
on 2006-10-26 23:50
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...
Thorsten L (Guest)
on 2006-10-27 00:24
(Received via mailing list)
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?
Alex W. (Guest)
on 2006-10-27 01:11
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 :(

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.
Brian H. (Guest)
on 2006-10-27 01:24
(Received via mailing list)
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
This topic is locked and can not be replied to.