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
[email protected]
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
[email protected]
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:
RMagick 1.15.0: class Draw. Also check out
the example for the Image#watermark method:
RMagick 1.15.0: class Image (instance methods, part 3) and the
example for the Image#mask attribute:
RMagick 1.15.0: class Image (attribute methods). These
last two require that you have RMagick 1.14.0 or later.
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?
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
[email protected]
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
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.
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