Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2007-11-16 22:25:47

iblastoff
Plugin Author
From: Toronto
Registered: 2006-06-11
Posts: 1,197
Website

Re: create watermark on the fly in PHP?

well you kind of need to upload the unwatermarked version in order to use php to create a watermark on it.

and of course you could just apply watermarks manually, but then again you could also update html files manually without having to use a cms as well :) just like you can use css to apply drop shadows to all of your images without having to manually add them. also if you’re planning on having a ton of images, it doesn’t make much sense to have to manually add a watermark to each one (of course you could create some batch automated action with photoshop but thats another issue/scope)

Offline

#14 2007-11-17 04:45:34

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: create watermark on the fly in PHP?

Why not combine both ideas?

Use the plugin to process your original uploaded image; creating a watermarked version that overwrites the original upload.

No need to store extra images. No need to protect directory. No need for mod_rewrite editing.


Steve

Offline

#15 2007-11-17 05:56:07

JonahC
Member
From: Toronto
Registered: 2007-09-23
Posts: 39
Website

Re: create watermark on the fly in PHP?

I like that idea. Currently, I use a photoshop batch action to apply watermark to all pictures. Then I use fpx_image_import to upload, rename the jpeg, create thumbnail anyway so why not have it apply watermark as well—all in one plugin. I don’t have to do the photoshop thing anymore. I find though that I can control the sharpening and compression in photoshop better than using tp….


Jonah Calinawan
www.foodportraits.com

Offline

#16 2007-11-17 09:50:38

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,615
GitHub Twitter

Re: create watermark on the fly in PHP?

net-carver wrote:

Why not combine both ideas?
Use the plugin to process your original uploaded image; creating a watermarked version that overwrites the original upload.
No need to store extra images. No need to protect directory. No need for mod_rewrite editing.

Absolutly!

The purpose is to protect images from visitors copies. From this point of view, if the user want to protect his images, we don’t need to keep original versions. No need to protect the directory at all. Of course, Photoshop batch processing make the rule… but it is a waste of times. No?

There are lot of good ideas in this topic. Keep going guys!

Best regards,

Last edited by Pat64 (2007-11-17 09:51:30)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#17 2007-11-17 11:55:55

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: create watermark on the fly in PHP?

The reason for keeping a copy of the original copy is for thumbnail creation, if you want to change thumb dimensions (or create a thumbnail) after uploading the original image. This assumes that you don’t want the thumbnail watermarked. Also, having the original image, makes it possible to change the watermark and regenerate the watermarked images without having to upload them all again.

Offline

#18 2007-11-17 12:24:58

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: create watermark on the fly in PHP?

ruud wrote:

The reason for keeping a copy of the original copy is for thumbnail creation, if you want to change thumb dimensions (or create a thumbnail) after uploading the original image. This assumes that you don’t want the thumbnail watermarked. Also, having the original image, makes it possible to change the watermark and regenerate the watermarked images without having to upload them all again.

All true! If that’s the case your solution is good for sites with a lot of images where you don’t want watermarked thumbnails.

So that leaves a simplified scenario for sites where you either…

  1. don’t anticipate the need to re-work a thumbnail
  2. don’t care about a watermark appearing in the thumbnails

And these two scenarios can be simplified :)

It would be possible for such a plugin to create unmarked thumbnails before the original image was overwritten with a watermarked version.

Last edited by net-carver (2007-11-17 12:27:13)


Steve

Offline

#19 2007-11-18 19:35:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,275
Website GitHub

Re: create watermark on the fly in PHP?

Eeek! I go away for a day and there’s a post snowstorm :-)

@ruud:

Isn’t this a bit CPU-intensive when doing the watermarking real-time for each image request?

Kind of, but I haven’t noticed the degradation when I’ve been using the code via mod_rewrite on my test site. Sure, it creates a temporary image on-the fly, decides which of the watermarks to apply and merges them, but it’s pretty rapid; dependent of course on the size of the images in question and the server. I’ve not tried much above 1024×768 at the moment – and looking at various photography sites, that’s big for a web preview!

There is an issue with plugins such as smd_slimbox. The sab_wm_image plugin simply added a new tag that could watermark a single image ID. I would want to expand the capabilities to allow multiple images/categories to be watermarked (and of course those read from a custom field). But then we’re into the territory of galleries of watermarked images and would start duplicating code in smd_slimbox / aro_slideshow / wet_for_each_image / rss_thumbpop / etc. Not ideal.

And of course all these plugins write their thumbnails to the page using either TXP’s image() / thumbnail() functions, or write to the page directly from the code. As far as I can tell there’s no usable hook in the image() call (anyone confirm?), so the only solution for watermarking these galleries (currently) is to use mod_rewrite, or a redirect…

keep both original and watermarked images in the images directory, redirecting all the requests for 1.jpg automatically to 1.watermarked.jpg using mod_redirect.

Yep, would work fine apart from the obvious space issue that JonahC mentioned. And of course, it’s not a TXP solution but a server config solution; some people might not have that luxury or prefer not to hack.

@JonahC:

Why not just upload a watermarked image right from the start?

Again, a perfectly acceptable use and I’m sure many people will do this. If they have forked out anything up to $800 for Photoshop or an equivalent. Maybe photographers do that as standard, but if you’re running a site for photographers or mere mortals to display their work, like iblastoff said it might be useful to ease the burden on them having to post-process their own files solely for copyright reasons.

@net-carver:

Use the plugin to process your original uploaded image; creating a watermarked version that overwrites the original upload.

Also a great idea. If there’s a hook in the file-upload process – I haven’t checked – then that’s possible. Otherwise it’s a hassle (for me, I’ve not reached that level yet!) to add a whole new screen and manage it, essentally replicating most of the functionality already available. There’s also the issue of interfacing with fpx_image_import, among others, and of course glx_admin_image which I use extensively. I don’t know if they use the standard upload/image functions in TXP or their own custom versions.

As ruud mentioned, thumbnail creation/editing requires an unmodified copy. And applying a full-size watermark to a thumbnail is probably rather unnecessary in most cases, in addition to being difficult to scale successfully within a suitable time-frame. Uploading a small thumbnail-sized watermark is a possibility.

@all:
From the sheer number of posts and use cases presented here, it’s apparent there are many different things people expect from a watermarking solution. So a system that could grow with the complexity of an individual site and offer different functionality depending on the level of expertise of the site builder is a must.

So what about, in no particular order:

  1. A fairly simple drop-in-replacement tag like sab_wm_image that offers the ability to watermark an image on-the-fly. This should be useful with wet_for_each_image or one-by-one image solutions.
  2. Some ability to specify different thumbnails depending on image size. Not vital because small images will just have the watermark cropped, but possibly useful if anyone thinks it has merit. Would probably require multiple copies of watermarks to be uploaded with specific filename parts (e.g. mywm_1024x768.jpg), otherwise the code to refactor the image starts taking too much time. Could specify a hierarchy of images, which would try each successive image in turn until it found one or ended up at the ‘default’ watermark, thus degrading semi-gracefully depending on how much effort the site owner/author wished to put into making watermarks.
  3. A thumbnail gallery plugin like the (hopefully) upcoming smd_thumbs that has the ability to offer fullsize or watermarked image galleries. My goal with smd_thumbs is to allow plugin authors to hook into it, thus being able to write layers around it to provide varying effects without having to reinvent the gallery generation bit. Think wet_for_each_image with knobs on. One such “layer” might be watermarking (or it could be built in, I haven’t decided)
  4. A system that works in tandem with the watermarking plugin(s) such that images can be tagged to indicate they are either a) already watermarked by the author (i.e. don’t apply another one), or b) require a watermark to be applied on-the-fly, along with a pointer to the relevant watermark to be used. This would benefit photo gallery sites from multiple artists who could each supply their own watermark, or do the donkey work themselves, or let site admins run the pics through photoshop. Gives per-photo control over watermarking and could be implemented as simply as uploading the images into sub-directories and telling the plugin which are which.
  5. Investigating integration with mass uploading/thumbnailing plugins.
  6. Providing instructions on using mod_redirect if people are happy to upload more than one image.
  7. Making the watermark.php script available standalone so it can be uploaded to a site, along with instructions on where changes can be made to the code if necessary, and examples of setting up mod_rewrite to achieve on-the-fly watermarking of all images on directories and file formats of your choosing.

What are your thoughts on some/all of those? Any more ideas? It’s more of a series of watermarking solutions wrapped in a package. Site authors choose which they prefer to fit their chosen site/expertise/daring :-)

Off the top of my head I envisage 1, 6 and 7 to be pretty simple for starters. 2 should be quite easy and could be built into 1. Option 3 is work in progress on my behalf and is at the mercy of my free time, but I really want it. 4 is not particularly tricky and could again be built into 1 and/or 3. Option 5 is probably out of my league right now depending on how the plugins have been coded. If anyone has any thoughts, please share.

I’ll step out of the way now. Let the bun-fight commence :-D

Last edited by Bloke (2007-11-18 19:40:03)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#20 2007-11-18 20:11:44

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,615
GitHub Twitter

Re: create watermark on the fly in PHP?

Oops. What a long post, Stef! Very professional, too.

Like you said, personnaly option #7 could be very usefull depending what kind of solution everyone choose to built their own images galleries. As you explain, the problem with images copies is very important for photographers.
In other hand, you (must) know there are lot of many options to create watermarks. Some use a copyright sentence and this kind of script use some true type fonts to render watermarks. It will be a solution for the problem you said in option #2.
I don’t think thumbnails need to be watermarked because nobody can use a 72/92 dpi small image.

Cheers,


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#21 2007-11-18 22:30:58

JonahC
Member
From: Toronto
Registered: 2007-09-23
Posts: 39
Website

Re: create watermark on the fly in PHP?

Hi-

I’m a stock photographer licensing images of food through my website so I would be very interested in this plugin. For now I’ve decided to watermark the main image and thumbnail (although I go back and forth on this issue). As I mentioned in an earlier post, I use photoshop to apply a watermark before I upload the images to txp. I upload the images at the maximum size that I want (400px wide) and let fpx_image_import create the thumbnail which is at 195px wide. So for me both the main image and the thumbnail have watermarks. I’m very new to textpattern, like 2 months, and I really love it, it’s so easy to use. From a photographer point of view, I think whatever you do, it would be good if you include these capabilities (just suggestions) :)

1. I think it’s important to give user an option to watermark both main image and thumbnail. I know it may be overkill for some. But I think this is important. Who could use a thumbnail anyway? I think especially for website use, a thumbnail is very valuable. Getty images is now licensing images (180×150 pixel) for $49 a pop so a thumbnail has value.

2. Could the watermark be applied at varying intensities? Like 50% 75% 85% 95% transparency? I used to use a program that only had 25%, 50%, 75%, 100% transparency. I think 75% was still too much watermarking but obviously 100% was useless (the watermark was essentialy non-existent). If there’s more granularity in the transparency that would be cool.

3. Most watermarks are done where you apply some image (jpeg etc) over the image which are then merged together. I think a better watermark would be one that uses the bevel effect. I think this is harder to implement without using photoshop, but if this could be done, then I think it might be better because you don’t have to analyze whether the picture is dark or light and apply the appropriate watermark. If this can’t be done, well ok, I can dream can’t I? :)

4. An option where you can specify where the watermark will be placed would be great as well. top-left, Top-middle, top right, middle, bottom-left, bottom-right. You could also specify an pixel offset x & y from the edges would be great. This might be hard. If it is – middle would probably work the best.

This interface from a program that I used to use might be helpful for ideas:


Jonah Calinawan
www.foodportraits.com

Offline

#22 2007-11-19 09:38:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,275
Website GitHub

Re: create watermark on the fly in PHP?

@pat64:

there are lot of many options to create watermarks. Some use a copyright sentence

Good point, I forgot to mention that. I have this built into my current solution, I’m just not using it right now. There are the usual font rendering issues but these can usually be circumvented by using a standard, boring, widely web-available font. But some servers just hate some fonts, so the ability to specify a font name/family would be useful.

The difficulty with a traditional text solution is that if you need to vary the text you can’t very easily. In your original PHP solution, the image to be watermarked is passed as an option to the script and the rest (e.g. the watermark image filename) is hard-coded. The text to apply would also require hard-coding in this case, because passing it as a parameter to the script means potentially any text could be rendered over the image.

This presents a problem because in a multi-photographer showcase site there has to be a way of varying the text somehow. The obvious solution is to have the text stored with the image (or a pointer to a text string in the database so it can be re-used) in a similar manner to the way I suggested that a watermark image might be specified. A plugin has access to this information and as long as the standalone watermark.php script can “see” the database somehow, this should be possible. Some testing required here.

Using words instead of an image has a few advantages and a few disadvantages which I’ll get to in a minute.

@JonahC:

Thanks for the run-down on how you use watermarking. Very useful when designing a system to have real-world cases.

> for me both the main image and the thumbnail have watermarks.

At 195px, I can see it’s a good idea! Thinking about it now, ‘thumbnail’ is purely a semantic term because in reality a thumbnail could be 1600×1200 so it makes sense to be able to watermark both. Didn’t realise Getty licence thumbnails. I suppose if you were to be selling clipart or web buttons then it’s important, so yes, a very good point.

Could the watermark be applied at varying intensities? Like 50% 75% 85% 95% transparency?

The way it’s set up at the moment, the watermark image itself is saved as a transparent png/gif and you pick the transparency when you create the image. This is not ideal but it works for most images.

I have not yet played with adjusting the alpha settings when applying an image in real-time. I should think the gd library that is used to merge the images has the option to apply opacity so perhaps this is something the script could do. I’ll investigate. In the event it can be done, specifying the opacity as a plugin option is easy. Quite how it would be specified with the standalone script is something that will require some thought. Perhaps some global prefs that could be overridden per-image if required.

Most watermarks are done where you apply some image (jpeg etc) over the image which are then merged together. I think a better watermark would be one that uses the bevel effect.

Agreed. There’s no reason your watermark image couldn’t have the bevel applied in the first place of course! And the gd library has an ‘emboss’ filter available, which is close :-)

Whether a text string can also have the filter applied at run-time and whether it impacts speed I don’t know. The same problem with scaling applies with text as to images. The size of the font chosen needs to be dependent on the image being watermarked; else it looks puny on a massive image or you only see one letter on a thumbnail.

Currently I haven’t figured out how to do that on-the-fly. I just set the font size (hard-coded) and make sure all images are roughly the same size.

if this could be done, then I think it might be better because you don’t have to analyze whether the picture is dark or light

True. Definitely worth some thought and experimentation to compare the relative speeds between the techniques. Or offer a choice of image or text, like your screen shot shows.

An option where you can specify where the watermark will be placed would be great as well.

Yes. Again, position is hard-coded at present but should be overridable. You have all the usual suspects available that you mentioned, plus centred in either direction. With text you are restricted (I think) to having it horizontally or vertically so if you wanted a diagonal word it would have to be an image.

Thanks for the screenshot. Looks like pretty much every conceivable option is covered there. If we can build a system that has all those prefs and can apply them to a variety of image sizes on-the-fly without degrading the response time it would be wicked.

Experiment mode on


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#23 2008-02-23 00:12:30

cuda
Member
From: Georgia, USA
Registered: 2008-02-06
Posts: 70
Website

Re: create watermark on the fly in PHP?

Bloke——just wondering if you still plan on creating this as a plugin…..I am looking to use this to overlay homes for sale images with “Sold” or “Reduced” etc….. not as a standard water

Thanks your plugins are truly great!

Offline

#24 2008-02-23 00:38:14

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,275
Website GitHub

Re: create watermark on the fly in PHP?

Yes, now smd_gallery is in place (well, nearly) I’m going to tackle this next.

I wanted smd_gallery to be able to use forms so you could use smd_watermark to apply watermarks to any pics you liked, or use it as a simple global script to watermark everything you ask, without discrimination.

I’ll probably release it in a few phases; your use case should fit nicely into phase 1 so you shouldn’t have to wait too long.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB