I create watermarks for imagecache.
I change imagecache module to do this.
Now you can:
1. You can use temp layar.
2. You can set background size and color
3. You can merge images and use transparence
4. You can use watermarks (with *.png files)

Link:
http://drupal.ru/files/imagecache.zip
Settings exampes:
http://drupal.ru/files/settings1.rar
http://drupal.ru/files/settings2.rar

I hope to this changes be useful in imagecach module and will be in imagecache2.

P.S.
Sory for my English.

Comments

Dimm’s picture

5. You can set background image.
6. You can copy main image to background often (1, 2,..,10,...100 time) in different place.
7. You can copy many images fom files to background or over main image.

quicksketch’s picture

Status: Active » Needs work

You'll need to post your changes as a patch for any chance for the changes to be included. http://drupal.org/patch/create

Dimm’s picture

StatusFileSize
new17.74 KB

I create imagecache.patch.

texas-bronius’s picture

thanks for this-- checking it out now.
Two little requests:
- please provide a little documentation
- please add a few more items to the prompting help list below "Add a new action.." drop list in imagecache config screen

Will follow-up with other observations if I figure out how to use this cool feature!

texas-bronius’s picture

I get it! Or at least I can get my watermark to show. Here's some help to anyone test-driving the watermark for imagecache patch.

Concepts to grasp:
- "image" refers to the uploaded image in imagecache as patched by the above patch
- "templayer" is a server-memory-resident workspace image and can be thought of as a canvas. You define its properties like base color and dimensions before beginning.
- stack operations and images as if layering in photoshop in order of "weight" (or "Bec" in the screenshots at the top of this thread). Crop just the uploaded image by doing that first, or the composited image by doing it at the end.

Steps to get a simple png to overlay an image:
1. upload watermark image to drupal site root files directory
2. get into admin imagecache
- create preset: I named mine "water-thumb" here.
- create templayer: this is the working canvas; set overall output image dimensions, set colors to 0's for black bg, set weight -10
- create scale: scales the uploaded image to desired dimensions; set dimensions, set weight -9
- copy image to templayer (image2templayer): copies image onto the "working canvas"; center, center, 100 alpha, set weight -8
- copy file to temp layer (file2templayer): copies watermark image from file onto the working canvas; filename is relative to files dir, bottom, right, 100 alpha, set weight -7
- swap templayer and image (swap_image_and_templayer): makes canvas the "working image in imagecache"; all operations after this now affect the composited image (like a final crop if you choose).
3. test the imagecache image in a url something like:
http://your-drupal-site/files/imagecache/water-thumb/files/image/viperfish.jpg

Thanks for this great enhancement to imagecache. I look forward to watching (helping?) it reach maturity.

texas-bronius’s picture

I have a better grasp of this nifty module now. My opinion: way cool, gonna love the new feature, but it's not module-ready. I would like to help get it there in whatever way I can.

Lacking:
- documentation
- on-screen guides (even just the little help comments that show below form fields)

Question:
- Would it be possible to get temp-layer to always match the dimensions of the uploaded image? As it stands, I get templayer borders around my non-square uploaded images.

Dimm’s picture

"Question:
- Would it be possible to get temp-layer to always match the dimensions of the uploaded image? As it stands, I get templayer borders around my non-square uploaded images."
Try to use temp-layer scale as 110%.

I have no time now.
I need help to finish this patch.

To do:
1. Upload *.png files.
2. Variable jpg-compression.
3. Integration to http://drupal.org/node/141370 !!!
4. Text watermarks (text make by php-code).
5. Select watermarks image by php-code.
6. If-else action to apply different actions to image.
7. Unlimite number of temp-layers.

BrightLoudNoise’s picture

This has a lot of potential, I'd propose the following for the action names:

  1. define canvas (templayer)
    Descriptive Text: "Define the size of the working canvas and background color, this controls the dimensions of the output image"
  2. scale (already exists)
    Descriptive Text possibilities:
    • scales the source image, should we suggest that these values should generally be the same size or smaller as the canvas size?
    • Otherwise we could put a recommendation in the canvas description, that it should be larger than the following scale/crop action?
  3. place source image (image2templayer)
    Descriptive Text: "Places the source image onto the canvas for compositing"
  4. apply overlay (file2templayer)
    Descriptive text: "Choose the image you wish to use as an overlay, and position it in a layer on top of the source image."
  5. merge layers (swap_image_and_templayer)
    Descriptive text "Merges all layers, subsequent actions will be applied to the composited image."

Nice to haves:

  • Add ability to upload watermark image from within action.
  • Bundle with a demonstration watermark preset that you can then edit
vipconsult’s picture

Is there any way to resize the watermark accordingly to the image that is put into ?

Example: Scale the image to 300x300 -watermark =100x100 ; Scale image to 100x100 - watermark scaled automatical to 30x30

Thanks

Dimm’s picture

StatusFileSize
new11.09 KB

imagecache_watermarks_patch v0.12

Features:
1. Watermarks.
2. Text watermarks.
3. You can define same canvas.
4. You can make same copy of source image to canvas (different size each copy of source image).
5. You can make same copy of image from file to canvas (different size each copy of image from file).
6. You can use php code to change same parameters.
7. Replace source image by file (To resize watermark file for example).

Usage:
To overlay watermark:
1. Define canvas
2. Scale source image
3. Overlay: source image to canvas
4. Overlay: file image to canvas (watermark)
5. Return canvas

To overlay text watermark:
1. Define canvas
2. Scale source image
3. Overlay: source image to canvas
4. Overlay: text to canvas
5. Return canvas

To resize watermark and overlay watermark:
1. Define canvas
2. Scale source image
3. Overlay: source image to canvas
4. Replace source image by file (watermark)
5. Scale source image
6. Overlay: file image to canvas (watermark)
7. Return canvas

To strestus
"Is there any way to resize the watermark accordingly to the image that is put into ?"
7. Replace source image by file (To resize watermark file for example).

Christopher Herberte’s picture

AWESOME WORK!!!
Subscribe. +1 x100

Dimm’s picture

StatusFileSize
new284.2 KB

imagecache_watermarks_patch v0.13

Features:

8. Now you can overlay text watermarks as $node->title and other...
9. It made by pass same variables to imagecach module by adding "?nid=123" string to sourse image path "files/images/foto.jpg"

Usage:
print theme('imagecache', 'my1', "files/images/". $item['filename']."?"."nid=".$node->nid, $node->title, $node->title);

It make code as
href="files/images/foto.jpg?nid=123"
- only first time.
After, if rezult image is made, it make code whithout "?nid=123" as:
href="files/images/foto.jpg"

Usage:
To overlay $node->title watermark:
1. Define canvas
2. Scale source image
3. Overlay: source image to canvas
4. Overlay: text to canvas
Php code(example):

$nid = isset($_GET['nid']) ? $_GET['nid'] : '';
if($nid && is_numeric($nid)){
$node=node_load($nid);
$action['data']['text']=$node->title;
}

5. Return canvas

dopry’s picture

Version: 5.x-1.3 » 6.x-2.x-dev

@Dimm,
Awesome work... I really want to integrate some of this into imagecache.. You present some really good ideas especially with the 'canvases' I prefer to think of them as 'layers'... I'm going to have to spend some time reviewing your work and the other watermark patch. this style interface is a little more complicated than I want imagecache to be for this version... I'd prefer watermark to be a simple to setup function.

I'd appreciate it if you could re-roll the patch without all the commented out lines of code... They noise is hard for me to read around.

.darrel.

Dimm’s picture

StatusFileSize
new283.73 KB

@dopry
Ok
imagecache_watermarks_patch_v014.zip - without all the commented out lines of code
I am glad to be useful.

anantagati’s picture

Status: Needs work » Needs review
Tim99’s picture

Will that be officially integrated into Imagecache in the near future?

Tim99’s picture

Will that be officially integrated into Imagecache in the near future?

OpenChimp’s picture

Just want to say that this sounds awesome! I probably won't have any immediate use for it, but the potential of this is amazing. Great stuff!

yeeloon’s picture

Hi!

Can you attached the complete zipped version of this "imagecache watermark" module, as I couldn't get it to work...

Please let me know if this actually can be done?

Thanks.
yeeloon

Dimm’s picture

StatusFileSize
new294.35 KB
Dimm’s picture

If you use text watermarks and you need to change the text in the picture after updating node then take this code as example and past it to imagecach.module:

function imagecache_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'update':
  drupal_set_message(t('Delete images in imagecach.'));
  $presets = _imagecache_get_presets();
  $path = $node->field_products_image[0][filepath];
  foreach ($presets as $presetid => $presetname) {
    $ipath = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
  	if (is_file($ipath)) {
		file_delete($ipath);
    }
  }
      break;
  }
}

anantagati’s picture

Status: Needs review » Needs work

I am using patch from #14 and it works good for image watermarks. But text watermarks doesn't work.

1. scale
2. define_canvas
3. overlay_source_image_to_canvas
4. overlay_file_image_to_canvas (or for text: overlay_text_to_canvas)
5. return_canvas
Dimm’s picture

2anantagati: is font file in "file" directory?

anantagati’s picture

Yes.

Path to files directory set in admin/settings/file-system is: "files"
Font "arial.ttf" is directly under directory "files".

Otherwise with image watermarks it works nice. I am using Xampp on Windows XP.

Dimm’s picture

StatusFileSize
new57.3 KB

Example.

jpetso’s picture

Title: I create watermarks for imagecache » Create watermarks for imagecache

Issue #112539 was marked as a duplicate of this issue.

poilf’s picture

This thing is totally awesome and should really get into the imagecache module!
But it generates jpegs with very low quality. Is there a way to change the quality settings?

BTW: the Canvas thing is cool, but i think most people just need to put a png over the picture, nothing more. Maybe the usability of this patch will be _much_ more easier if there would be (besides the other actions) one simple action that is called something like "Put watermark image over source image" that does exactly this and you're done. The hassling with the canvas stuff really eated up my time.

poilf’s picture

one more thing: transparency = 0 means full transparency and 100 means no transparency. Isn't this wrong?
This should called visibility or the numbers should be flipped.

jpetso’s picture

I believe opacity, not visibility, is the popular term for 100% of non-transparency.

anantagati’s picture

So I tried one time more text watermark and found that when when 'X offset' and 'Y offset' has values in pixels it works. But when there is for example word 'center' it doesn't work.

psynaptic’s picture

Title: Create watermarks for imagecache » Excellent feature

This is superb! I have successfully managed to get image watermarking for all product image derivatives on my Ubercart based test site. One thing I also needed to do which was outside the instructions above was to create a non-scaling imagecache preset to apply the watermark to the full-sized image (shown when a thickbox link was clicked).

My test site is using XAMPP on OS X and I will be migrating it to a live site today.

Thanks a lot Dimm! Much appreciated.

jpetso’s picture

Title: Excellent feature » Create watermarks for imagecache

Don't change the issue title, please.

psynaptic’s picture

Sorry, didn't realise that's what I was doing. Thanks for pointing it out to me.

Edit: I'd just like to add that I migrated the feature to my live site and everything works wonderfully. I hope this gets included in the imagecache module.

anantagati’s picture

When watermark file does not exist, images are not generated, but in log is not possible to find reason.

It should write message to log, something like: "watermark.png not found".

psynaptic’s picture

I found this quite hard to get to grips with so I spent a couple of days getting my head together and have written a tutorial on Watermarking (Ubercart) product images. The tutorial could also be used as a general guide to help users struggling with this. I tried to write it so watermarks were applied in as flexible a way as I could find. Feedback welcome. Hope it helps someone.

Dimm’s picture

The next version of watermarks will be for ImageCache 2.
When I have free time will be.

dopry’s picture

Dimm, just so you don't lose hope... This is still on my radar... I haven't included it yet because it is a major change to the way imagecache deals with images... I really want the layering stuff in... I almost feel it is a better fit in imageAPI, but I really need to think about the integration and where it fits exactly and I haven't have time. Is there any chance you will be making it to DrupalCon? It would be awesome to talk about this in person.

.darrel.

Dimm’s picture

Ok, I will try.

George2’s picture

great - thanks. having problems with text watermarks as above. it doesn't seem to convert 'left', 'top' etc into the necessary ints. also, i'd like to see an opacity setting on the text watermark as well. and yes, i agree the label should be opacity and not transparency. 100% transparent is see-through, not opaque :)

this is really great because it allows me to have different watermarks for different presets, so can reuse the same images for different sites.

thanks for something i was just about to start slaving on today!

capitano83’s picture

Hi,
guys....great threads !!! :)

But i need help... i need the instructions was to create a non-scaling imagecache preset to apply the watermark to the full-sized image (shown when a thickbox link was clicked).

can everyone help me...plssss?

Best regards,
Max

Dimm’s picture

1. Make non-scaling imagecache preset to apply the watermark to the full-sized image.
2. Change node.tpl to print thickbox link to images of this preset.

capitano83’s picture

Sorry, im a newbie!! :)

Ok for make a non-scaling imagechace preset to apply a watermark full-sized image. :)

But can you explain me (if necessary with an example) the second point????
What can i do with node.tpl????

Tnx a lot,best regards,
Max

Dimm’s picture

file^ themes/you_theme/node.tpl.php

foreach ((array)$field_>>>>>image_field_name<<<<< as $item) { 
print '<a href="'. url('node/'.  $node->nid).'" title='.$node->title.' border="0">';
print theme('imagecache', 'preset_name', "files/dir_whith_images/". $item['filename'], $node->title, $node->title);
print '</a>';
}
psynaptic’s picture

capitano83,

what you have asked is explained in the tutorial: http://drupal.org/node/214454

Dimm’s picture

StatusFileSize
new332.4 KB

imagecache_watermarks_patch v0.15

10. No imagecache if image is not exist.

function theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL) {
if($path){
  $attributes = drupal_attributes($attributes);
  $var_array = explode("?",$path);
  $path=$var_array[0]; 
  $vars=$var_array[1];
  $destination = file_create_path() .'/imagecache/'. $namespace.'/'. $path;
  if($vars){
  if (is_file($destination)) {
	  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
  }else{
	  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path . '?'.$vars);
  }
  }else{
	  $imagecache_path = file_create_url(file_directory_path() .'/imagecache/'. $namespace .'/'. $path);
  }

  return '<img src="'. $imagecache_path .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $attributes .' />';
  }else{
  return false;
  }

}

11. "Transparency" change to "opacity".

jpetso’s picture

Arial is copyrighted by Microsoft and can't be distributed together with GPL software. I think that also applies to Impact, but I'm not sure. It would be cool to have a GPL compatible font instead, or just asking the users to upload a .ttf file by themselves.

Dimm’s picture

StatusFileSize
new60.11 KB

to: jpetso
You right.
imagecache_watermarks_v016.zip - without copyrighted fonts.

pingers’s picture

StatusFileSize
new738 bytes

Just to throw a spanner in the works I just created a watermark patch, before I checked here ... maybe this is just confusing to have another patch to try... but I like the simplicity of my patch. Probably needs some work... but it works for me.

The patch allows adding another filter by which you can use an image as a watermark and specify it's offset. PNG transparency works.

Praise or constructively criticize at your leisure :)

Farreres’s picture

Come on, people. There are two different threads offering the same solution. Could someone with the knowledge do something to merge them all and give us finally this feature?

The other thread is http://drupal.org/node/173759

dman’s picture

I'm afraid #47 isn't much of a patch. How much criticism can you take? I think the best response is the classic l-user problem description : "It doesn't work".

to be more constructive - the patch you attached contains a single string change and zero functionality ;-)

I'm still wishing for someone to converge on this feature also, but I don't think that the job Dimm has been doing in this thread is compatible with the improved imagecache 'actions' api. I may be wrong, so I'll see if I can get it going.

dman’s picture

Yeah, OK. Dimms stuff looks impressive. But it's against DRUPAL-5--1-3 , while the imagecache module DRUPAL-5--2 changed the API entirely (to allow for contrib actions like these better).
Shit.
Maybe I'll see if I can port it...

dman’s picture

StatusFileSize
new4.75 KB

OK ... Here's a rewrite of Dimms examples - converted to the new modular API!

I left out the concept of multiple canvasses, and the advanced php code option, as they don't fit in the new way of doing things ...
They could - the advanced code process for example can now be a great help with imageAPI - but it was out of scope for getting this job up and running.
So we now have
- image overlay, inc alpha (watermark)
- image background (frames etc)
- text overlay (copyright)
... and
- solid color base ... because it was the first action I ported hoping it would be easy.

This can now be installed as a helper module to imagecache - but only alongside imagecache 5.x-2
So if you are keen to upgrade imagecache, these functions will work!

In theory. I've not been able to fully test all the corners yet. This was mostly an emulation of existing code. I didn't stop to actually think about better ways of doing things. I'm sure there's a few...

Note - I want this to go towards the imagecache project as a contrib, not a stand-alone.
TODO includes splitting the code off into libraries to lighten it up a bit, but only once the code review is done.

Farreres’s picture

Is this something to path imagecache or you are yet to do some other tasks before it's useful? It would be nice to have it integrated in the next release, be it dev or official.

dman’s picture

Imagecache 5--2 is in alpha. Up to you whether you want to start using it.
BUT the point is that imagecache 5--2 has split off the actions into contrib libraries, so there's no longer so much pain in 'integrating' new features like this. We should be able to just pick and choose among them.

I think it's useful right now (against the alpha update) but there are a few growing pains - like I just found I need to flush the preset cache on a clean system etc ...
If anyone wants to test the imagecache dev release - first without my additions - and give some feedback ("it works for me") then that dev release version can be promoted to a supported release.
THEN we can test these additions against it and get that rolled in also.

Please, just upgrade imagecache to the 5--2 version (with imagecache_ui and image_api) and tell us it's OK. (in the other issue thread) Based on that feedback, the next rollout can progress.

Dimm’s picture

To dman: Good work!

Farreres’s picture

Sorry Dman, excuses, which is this other issue thread to communicate our experiences with imagecache 2 alpha? I am using it right now and it works ok but I would better explain it in the appropriate issue thread.

dman’s picture

Status: Needs work » Needs review

Hm. OK, there wasn't really one.
http://drupal.org/node/232618
Here you go!

sgriffin’s picture

imagecache_canvasactions requires imageapi and imageapi requires php5 FYI.

sgriffin’s picture

imagecache replacements #45 or #47 are working great
Unfortunately, the documentation is a bit weird/lacking as well as the interface.
A good tutorial is here.
http://www.ubercart.org/docs/user/2504/watermarking_product_images
For a standard watermark, I did my normal scale as the highest action, and continued to "Add watermarking to full-sized images." listed in the article.
This would be the way to go if you dont have php5, otherwise #52 might work.

sgriffin’s picture

Another caveat, imagecache replacement does not work with the imagemagick toolkit.

z.stolar’s picture

Hi,

Can someone summarize the current state of watermarking with imagecache?

There are few issues open, maybe some need to be marked "duplicate" or "closed", so the efforts are better concentrated:
http://drupal.org/node/173759
http://drupal.org/node/184816 (this one)
http://drupal.org/node/212537 (less developed in the watermark direction, but looks good)

Thanks!

dman’s picture

StatusFileSize
new5 KB

As noted above. There are working things ready to go, but they've been pending a release of imagecache2.
Extensions to code in flux are painful to folk who are unable to patch.

However I'm currently using the attached module (only minor mods from the same one I converted earlier) successfully to get nice image-overlay and text watermarks.

The call went out for PEOPLE TO TEST imagecache 5--2 so we could call it stable. Then these will be added as contribs (I imagine)

z.stolar’s picture

@dopry: Can you please put a link to imagecache-2-beta on the project's page, so people know about it (and about the need to test it :-) )?

dopry’s picture

Status: Needs review » Closed (fixed)

@all: I've been thinking about this a lot lately... I would really like to see this as a seperate contrib module with package = ImageCache in the .info. Don't let me hold up getting it out. Eventually maybe we can roll it into core, but I have enough to do right now just managing the pipe lining and the modifications to imagecache/imageapi. I added all the actions hooks explicitly so people could build cool plugins to imagecache please use the ability...

I'm going to close this issue with hopes for it becoming it's own project.

dman’s picture

Absolutely cool with this being its own proj - that's what the hooks are for indeed.

All I want to know is ...

Are you happy with the imagecache v2 API? Is it stable enough for us to now start building on?
That's been the only concern from my POV.

If your only concern is the imageMagick commandline/platform stuff, but the hooks are how you intended tham, then I think we can indeed move ahead.
Dimm and I can open up this as imagecache_layers.module or something.

Dimm’s picture

Ok.

psynaptic’s picture

I think this is a great idea. We can have any number of modules dependant on imagecache and choose which to use for specific situations.

avolve’s picture

I am returning to looking for a watermark solution and might have missed some things in trying to catch up on recent developments.

I just wanted to mention (in case not known), that this breaks a 5.7 install (MAMP, OS X 10.4.11 PPC). All dependencies are installed. I know this is the HEAD version, i just thought i would give it a try.

I can provide a list of modules (not extensive for this test site) if this may help...

dman’s picture

Describe "this". Do you mean imagecache-2 or the latest additional module attached in this thread?
Describe "breaks" :-}

avolve’s picture

Perhaps you have identified the issue?? I have imagecache 5.x.1.5 (is v2 required?) and the head version of canvas actions— 'this' refers to canvas actions. By break, it gives a blank page after enabling the module.

I do not think it would be a memory issue as i had previously changed php memory to 200MB.

thx

mir-ink’s picture

nah nah and NAHH! :)

you watermark in the actual immage.. PS if you look allready lets you do this directly. there is no need for more than that.

check your plug in and do it right.. Its free and easy..

I make textuers for 3d games and ALL have my mark imbeded in them.

I sell them all over the place .. this is not a matter of drupal . its a matter of using the toys right :)

the marks are made in the orginal work see.

Up to you as how to inforce them.

I make verry good ones, and i make them to be used.. watermark YES .. dosent matter the use ..

Mirage (Ranting.. X-fidoOP 226)

PS: Its your hard work.. DO it :)

dman’s picture

@avolve
So just enabling it on the modules admin page takes down Drupal with no error messages in the log? And Drupal remains down until you remove the module? Is that what you are saying? Even without actually using the imagecache process?

But YES this requires the imagecache DRUPAL-5--2 dev version. That's the one that introduces plugin ability :)

@mir-inc ... WTF? I have a few thousand photos, and an editor who's uploading more from his camera. And had no graphic skills. Adding watermarks individually by hand (if that's what you mean, I can't really tell) is not an option.

avolve’s picture

@dman I have imagecache 2 installed now and i can see the extra settings for presets. With imagecache 5.x.1.5 the canvas actions module did break the drupal install as you described (sorry for not providing error logs).

Having resolved that, i have noted some issues with watermarks and larger images (even with my php memory set to 200MB in php.ini). The imagecache preset does not get generated. I can get the 'Add Overlay: file image to canvas (watermark)' to work on smaller images (320px wide works).

Any advice on this?
thx

@mir-inc My perception is that this module is designed to negate that a need to manually watermark images prior to upload. You can also make the images available without the watermark as well with (create a separate present, or link to the original image). In this sense, this module is time-saving than watermarking images prior to upload

dman’s picture

Right now I'm looking at ways to optimize the timeouts etc which are bugging me on my machine. But I've been successfully processing images bigger than 3.5 MB, 2400x1800px

... just not lots at a time. You may be hitting a timeout on your machine.
The image overlay with alpha blending is being done pixel-by-pixel ... which is painful. But this is because I encountered inconsistancies with the gd toolkit imagecopymerge function :(
It's certainly a strain on the machine.
I'm looking for better answers.

jdevries’s picture

I have upgraded to 5.x-2.0-rc1 and I'm trying to get watermarking working again by using the module in #62. I can successfully enable the Imagecache Canvas Actions module, but I don't appear to have any additional actions in the Imagecache presets. Do I need to take any additional steps that I'm missing to make the canvas actions available?

dman’s picture

Um, yes.
For some reason, the available actions are being agressively cached ... and although I attempt to 'flush' the list on install, it doesn't seem to work :-{

There is a line towards the top of the imagecache_canvasactions module with a comment about caching. Uncomment the line below it.
(line 44)

imagecache_action_definitions(TRUE);

Um, dopry, how did you see that working? I try calling it in the install hook, but I think that's just a bit too soon, as the module isn't actually available yet!
Maybe we could flush it every visit to the imagecache presets admin page?

Dimm’s picture

Status: Closed (fixed) » Active
StatusFileSize
new66.23 KB

imagecache_watermarks_patch v0.12

Features:
1. Watermarks.
2. Text watermarks.
3. You can define same canvas.
4. You can make same copy of source image to canvas (different size each copy of source image).
5. You can make same copy of image from file to canvas (different size each copy of image from file).
6. You can use php code to change same parameters.
7. Replace source image by file (To resize watermark file for example).

imagecache_watermarks_patch v0.13

Features:

8. Now you can overlay text watermarks as $node->title and other...
9. It made by pass same variables to imagecach module by adding "?nid=123" string to sourse image path "files/images/foto.jpg"

imagecache_watermarks_patch v0.14

If you use text watermarks and you need to change the text in the picture after updating node then take this code as example and past it to imagecach.module:


function imagecache_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'update':
  drupal_set_message(t('Delete images in imagecach.'));
  $presets = _imagecache_get_presets();
  $path = $node->field_products_image[0][filepath];
  foreach ($presets as $presetid => $presetname) {
    $ipath = file_directory_path() .'/imagecache/'. $presetname .'/'. $path;
      if (is_file($ipath)) {
        file_delete($ipath);
    }
  }
      break;
  }
}

imagecache_watermarks_patch v0.15

10. No imagecache if image is not exist.
11. "Transparency" change to "opacity".

imagecache_watermarks_patch v0.17
for imagecache-5.x-1.5

Dimm’s picture

imagecache_watermarks_patch v0.18
12. If image is not exist you can set default image.
Put this code to "Php code" field in first action (define_canvas).

if (!is_file($source)) {
$path='files/default_image.jpg';
}

TC44’s picture

subscribe

psicomante’s picture

If we create image with watermarks, we should find out a way to protect original images and possible presets without watermark, isn't it?

I think we can set some images "protected" from display as without watermark. In association with imagefield, some images can only be available in some preset and not in other.

Anyone is interested?

Sorry for my bad english.

dman’s picture

I've considered that issue in a recent project. Briefly.
It's much too hard. It's not imagecache's job to make that decision. You have to flag it another way, and then just not call or display the imagecache version for the ones you want to protect. Imagecache is just a pipeline. You ask - you get. Don't want it? Don't ask.

Your _original should always be available, and hopefully unwatermarked. Use your code to decide which derivative or cache preset to display. Based on your own logic. It's straightforward using image.module (just tag it). Dunno about imagefield. That's up to you.

PS, I'm adding another layer effect - underlay/background to this add-on, although it needs work to explain why. Oh ... And I promised to bundle it up into a project for everyone one day didn't I? OK, I'll try this weekend.

stella’s picture

Is there a version I should use for imagecache 5.x-2.0 ?

Cheers,
Stella

mw4ll4c3’s picture

StatusFileSize
new2.65 KB

Stella; I recently updated to imagecache2 on a site-in-progress; I'm just now wrapping up a simple watermarking plugin... it doesn't have any of the funky canvas tricks of dimm's build, but it's good at what it does (or what I've asked it to do thus far.)

Textual overlays are essentially one-for-one with imagecache_wm, just worked into the new 2.0 system.

Graphical overlays are a bit different, allowing selection of origins in both the source and destination images in addition to the x/y offsets. Easy example: selecting the bottom-right for both origins and specifying offsets (-10,-10) results in the bottom-right of the overlay being placed on a 10-pixel margin from the bottom right of the destination.

I propose, even if my system is lacking elsewhere (e.g. I didn't even think about pngs) that this origin/offset system is adopted to replace the original offset/keyword system... it's much more flexible, and strikes me as more intuitive. Even if my math and language need work, the concept is strong.

Note the two underscore-headed functions at the very bottom of the file; they're doing the actual, post-preparatory work until an equivalent is in the imageapi / toolkits.

Thanks again to dimm for all of his original work!

Farreres’s picture

It seems dman had no time to create a project. Could someone else pack everything Dimm has created and let us enjoy the pleasure of installing a new imagecache watermark package? Please :)

dman’s picture

StatusFileSize
new167.04 KB
new139.98 KB

HERE is an updated roll of both the imagecache watermarks (canvas) actions
AND the color actions (inc alpha effects)
... As stand-alone modules that integrate with imagecache 2 API.

This release was built against
imagecache: DRUPAL-5--2-0
imageapi: DRUPAL-5--1-1

Currently lacking slightly in docs and recipes, but it's been working well for me for a few months.
I'll attach a screenshot to give you an idea how I've been using it.

Yeah, this is worth a project. I'll set it up when I can be bothered fighting with CVS again.

In the meantime THESE WORK. And I guess can now be tested. Most of it will be HOWTOs I think. If anyone wants to share recipes, that'll be cool.

The function names may need to be cleaned up for code convention purposes, but all these actions are prefixed with just 'imagecache_' not 'imagecache_canvasactions_'* because that's too much typing.

It also includes a small patch to imagecache.module that gives you previews of the presets (as seen below). And a little more error-chacking paranoia. You may want to apply the patch - but it's optional.

Farreres’s picture

REALLY REALLY REALLY THANKS

Now having this with us we can start catching bugs. When you have time you can create the project. Thank you. The images are impressive :) Want to try as fast as possible!

dman’s picture

ps.
I agree with semicolon_jones that the offset mechanism can be updated a little more.
I had to pull some heuristics to make the text inset a bit also - rather than just 'bottom right' etc, so a better pattern would be good - although I haven't checked the code yet.
Plaintext is a bit cheap-looking however, so I'll be using PNGs with transparency for anything I do ... which means I can pad them out appropriately anyway - so the point is moot for me.

dman’s picture

Just before I go making anything ...
Is everyone happy with calling the action library project 'imagecache_actions' ? We can add to it as needed.

Oh, and BTW, there's a really cool way to use the watermark to do rounded corners, photo-corners, and possibly even patterned borders. I'll throw up a recipe example sometime.

All we are missing now is ... um, arbitrary PHP code (like Dimms first go had) and maybe rotation. Someone else can do those. :-)
Me, I'll look into using the 'file' parameter to pull some of the functions out into includes. It's a good feature, so I should use it.

Farreres’s picture

Now that you ask about possibilities for the project name, we are in time to contact the maintainer if this other module http://drupal.org/project/imagecache_colorblend to integrate it all in one big module so we don't have 20 modules for adding one action each, what do you think? It is another recent imagecache-related module.

About the name, I installed the module and I see it is MUCH MORE than just watermarking. It is clearly adding new actions to imagecache, so your name is ok with me: imagecache_actions.

I would like to see your solution to rounded corners. Right now I use rounded_corners module for this.

Antoine Lafontaine’s picture

I think imagecache_actions is a good name, but i wonder if "actions" is a bit too general for people unfamiliar with drupal (aka new users).

I didn't find imagecache as soon as I would have liked when i first got into contact with drupal since its name is not very good at communicating all that you can do with it. Since imagecache is there to stay, I feel that any imagecache_something module could help point in the direction of what imagecache can do and how it is so helpfull by providing more information in it's name. I'll give it a shot and most of my ideas are probably questionnable, but I feel that if we are to discuss about a name, that point should be considered.

here it goes:

imagecache_imagemanipulations
imagecache_manipulations
imagecache_pictureeffects
imagecache_actions_manipulations

Alright, I'm not really happy with all this, but I just want people to think a bit about this before choosing the final name. If a user is looking for image manipulations or picture effects... or something like that, he could get this module in their search result and, by looking at the dependencies, also get imagache, this could help make the world a better place!

Of course, if the name is already in use in the community, imagecache_actions would still be quite suitable.

Hope this helps fuel some ideas.

dman’s picture

I can't say I'm enamoured by those suggestions :-}

But you make a good point about findability.
Possibly 'actions' is a bit broad, and these days may be confused with the real drupal 'actions' api.

imagecache_processes?

We can keep 'imagecache_effects' in reserve for another set of 'effects' (blur,sharpen,artistic) as seen in image editors. And add it to this project.
Terminology is always going to be a pain here. Even using photoshop or whatever I can never remember which submenu 'levels' is in etc.

The bundle here contains two modules (there is no actual imagecache_actions.module)
The modules are named imagecache_coloractions.module, imagecache_canvasactions.module
Note - not 'layers' neccessarily. Technically it's not true multi-layer manipulation going on there - just overlays and underlays being slapped on the top or bottom in order, always working with just one combined base, flat image.

I think we can get a quick link from the imagecache home page referring to these extended utilities ;-)

Currently there is a small error in the watermark maths when overlaying transparent over transparent I'm aware of. There's also a hidden quirk whereby some (but not all) transparency effects convert the image invisibly from a jpg to a png (to continue allowing trans to work) but that needs documenting. There's a 'flatten' function provided to undo that at the end of the process. Basically needs some write-ups.

Antoine Lafontaine’s picture

Yeah, forget about my suggestions... hehe

But basically the findability was the thing that tickled me.

To tell the truth, processes or actions are quite good names I think, but both words have their meaning open to interpretation I'm afraid... and since effects would be used for another range of modules, I would say stick with actions since it's already been used (even if just in limited fashion) and it could even cover effects if needed. I think that imagecache by itself as a good enough status to bring attention to this module and, lets hope, the opposite will also be true.

Thanks for considering my ideas.

dman’s picture

Here we go!

Imagecache Actions

I needed to do a few tweaks to imageapi to get transparency working as good as it does now. I'll post them in another issue over there.

Antoine Lafontaine’s picture

Thank you dman for this!

I have been trying it out yesterday for about 3-4 hours. So far, so good. Result are consistent with how I expected it to work and I feel that even without a lot of documentation it is fairly easy to grasp the subtleties by trial and error. I guess that from now on issues will go over to the project page itself.

I almost forgot! Thanks you Dimm for the initial work on this.

avolve’s picture

Checking back, the results look very very good!

What is the news on processing times? I am hopiing (corectly assuming?) the approach has changed to overcome some of the earlier issues (or is it still pixel by pixel)? My main interest is (for now) in watermarking, though the other actions are very interesting and i can see the potential.

I will report back with any experiences worth sharing.

thanks for all the work put in!

z.stolar’s picture

I think it's time that one of the brave people who contributed us this long-waited module, will close this issue :-)
There is a new issue queue... http://drupal.org/project/issues/imagecache_actions

Thanks!!

jpetso’s picture

Status: Active » Fixed

Drupal doesn't award people who close issues, so anyone can do it with the same effect. Which means this issue is now *closed*.

Great work y'all! And of course special kudos to Dimm, dman, and dopry (that would make you "3d" :P ) for making this happen.

Dimm’s picture

Status: Fixed » Needs work

Issue is not *closed*.
1. I need imagecache-5.x-1.5
2. Not all features from imagecache_watermarks.patch translated to Imagecache Actions

dman’s picture

Version: 6.x-2.x-dev » 5.x-1.5

Dimm, you have CVS on imagecache_actions (as does dopry) if you want to joins us over there.

I'm not going to continue trying to do anything with imagecache1, as imagecache2 is the one that added the API that allows us to make these extensions available. If anyone is not keen to upgrade to imagecache2 as needed, I'd recommend they use your patch above, and live with it. I don't think there will/should be any more action on the imagecache1 branch.

What I currently have in imagecache_actions has evolved a long way from the initial patch posted in this thread in October. The entire callback process changed, and I've changed many things in testing. And I haven't followed the patches to the patch posted since (as imagecache1 was dying).

The 'features' I left out from Dimms imagecache1 version are (IIRC) the "add arbitrary php code" and the whole "retain multiple layers in processing memory" method.

#1 can be added as yet another add-on option in a new contrib, I think. It's certainly useful, but was out-of-scope.

#2 I simply couldn't use, is not supported by the imagecache/imageapi callbacks (although I guess it could be), and was able to get all the results I needed by using 'canvases' not 'layers' and sandwiching effects either under or over the base image. I could see where you were going with the concept, but I couldn't document it, or even understand how it should be used in practice.

I think there was one other process I couldn't understand or use, that I left out.
If you can document it and add it to the new module, that would be fine.

Oh yeah, and the 'default image' thing was added a while after I did the upgrade, I've not had a look at that. It's not part of the actions, and if anything, that should be a separate patch against imagecache.module, I think. A bit like my 'sample image' patch for the UI (as seen in the screenshots) that is also pending separately.

@avolve
The processing time is BAD. There's a quirk in versions of the gd(?) built-in image compositor that (in my test platforms at least) wasn't doing transparencies right, so the watermarking is still done using a script library that does it pixel-by-pixel. So that can be like 20seconds per high-res image :-(
THAT MAY BE POSSIBLE TO FIX given the right combination of setalphablending() etc calls, but I could not find it at the time. Or since. This is certainly sub-optimal.
Tested solutions are welcome!

Bits of this whole thing are still a bit ad-hoc, though I've been trying to standardize/abstract it a bit. My code, plus Dimms contributions, plus Doprys progress with imageapi all did things a little different at different times, WRT the interface, and especially color notation. I've changed/changing Dimms version from RGB-DEC to HEX notation (the UI currently shows both, which I'll phase out soon) and dopry has a hex-to-color conversion script which is almost, but not quite like the one I'm using. Obviously I prefer mine (which is keyed the same way the toolkit works) rather than indexed by number ... but I'm not challenging something that works!
I've yet to actually review the imageapi code and find bits I can re-use/improve on. I'm sure there's a few examples I can integrate. The meaty code in the image_actions module actually predates the imageapi altogether, so the parallal development may have created some cross-overs.
So there's bits of the code I've committed that still could be smoothed over, style-wise.

I won't close it then, but I'll roll this issue back to imagecache-5.x-1 if Dimm wants it to remain there, with the patch in question being Dimms own #78

Farreres’s picture

dman, you say GD has some quirks. What about imagemagick? I say it because I remember there was some imagemagick possibility for imageapi and if I have to wait 20 sec with GD, it can perhaps be faster with imagemagick API?

dman’s picture

good luck with that, I've not tried or tested it myself. In fact, some of the features probably just won't work with it yet. Support can be added by anyone who actually knows or uses imagemagick :-{

Farreres’s picture

Hmmm drupal.org/project/imagecache_actions has no project to install. It would be nice that someone uploaded things there, don't you think?

@dman: I have used imagemagick for some tasks and it's great, but I am not an experienced php programmer sorry. In any case, it would have the advantage of not overloading php, it's just calling an external program.

dman’s picture

The project http://drupal.org/node/264658 may not yet be accessible to folk without the ability to do CVS. I believe it takes a while for the release to be rolled into a tarball if you don't know how to run the appropriate command from your commandline (it's tagged DRUPAL-5--1, but is also HEAD). I think there are instructions in the handbook for installing from win32 etc if needed.

Imagemagick is a fine alternative I'd LIKE to see, but it requires different code by someone who knows what that different code is. Although it's 'just' calling another process, that process still needs to run somehow. In some cases in a forked thread. I'd like to think this can be done efficiently, but it's still under the auspices of the running PHP process, so whatever wins it provide are still essentially PHP-spawned jobs.
The win is not automatic by choosing a different library. It comes from invoking that library in a better way than I've found so far. Please let us know the better way to do it!

I LIKE imagemagick in theory , but have not sucessfully deployed it to hosts where I don't have root. Therefore it's not a solution I can recommend to most Drupal client sites. Trying to document that process was painful. Any workable instructions may be helpful, but I can't work around unknown hosts.

Please tell us how to get imagemagick working on a hosted site without root access! Then tell us what needs to happen to run it with the new commands! I can only so far contribute what works on the GD toolkit. Other extensions are optional extras.

I hope someone else knows more than me about imagemagick. They may be able to help.

dman’s picture

Status: Needs work » Closed (fixed)

Any further watermark issues should go to imagecache_actions. Closing

unrev.org’s picture

You can do this with the imagecache actions module

http://drupal.org/project/Imagecache_Actions