edu@ΣΔΕ

Basic Info

  • Domain:
  • Subdomain:
  • Topics:
  • Locations:
  • Education:
  • Slang:
  • Flamboyance:

Ranking

Θέματα

Mood Cloud

About This Page

  • Domain:
  • Subdomain:
  • Topics:
  • Locations:
  • Flamboyance:
  • Slang:
  • Education:

A quick tutorial for applying watermarks on images in drupal

Task:
A realtor's website with a lot of content (rentals, for sale, area info). Photos appear as thumbnails in the node page and lightbox is used to present them in a slideshow.

At the end of the project the client requests to watermark a copyright note on all images. Don't need to mention that re-uploading all their images was out of the question.

I decided to go ahead and put this tutorial together since I didn't manage to find any other tutorials out there.

So here it goes:

Versions:
Drupal 6.16

Modules:

- Started with:

  • Content Construction Kit (CCK) 6.x-2.6
  • Image 6.x-1.0-beta5
  • Lightbox2 6.x-1.9
  • Views 6.x-2.10
  • ImageField 6.x-3.3

- Had to add for the watermarks:

  • ImageAPI 6.x-1.8
  • ImageCache 6.x-2.0-beta10
  • ImageCache Actions 6.x-1.7

The ImageAPI GD2 module is the only enabled image toolkit. Drupal will use it for resizing, cropping and other image manipulations.


Step 1
Install the modules and enable the ImageAPI GD2 module.

Step 2
ImageCache - Add new preset
/admin/build/imagecache/list

Preset Namespace:  watermark
Actions: Overlay (watermark)    watermark.png x:right, y:bottom alpha:100%
You need to put your watermark.png file in the files directory

Step 3
Go to your content type's display fields form and choose watermark (see picture)
/admin/content/node-type/[you-content-type]/display

Or

Step 3
use contemplate to have even more power over presentation and do something like that:

(My content type's field that holds images is called... field_images)

Snippet in the Template of my content type:

<div id='thumbnails'>

<?php foreach ((array)$node->field_images as $item) {

    $real_filename= strrchr($item['filepath'],'/');

    /***
    Note: I used the strrchr to find the last occurrence of / in the filepath in order to get
    the real filename.

    ...   image/ckk modules don't update the field_image['filename'] variable
    when an image is overwritten (changing the actual filename to filename_x)
    ***/
?>
<a title="<?php print $item['data']['title'] ?>" href="http://www.example.com/sites/default/files/imagecache/watermark/<?php print $real_filename ?>" rel="lightshow[homes][<br /><?php print $item['data']['description'] ?><br />]" class="linkopacity"><IMG alt="<?php print $item['data']['description'] ?>" hspace=0 src="http://www.example.com/<?php print $item['filepath'] ?>" align=baseline border=0 width=80 height=60></a>
<?php } ?>
</div>

I hope this helps.