Hack 5. Leave a Watermark
Use the composite tool from ImageMagick to add custom watermarks to your images. Copy protection, particularly digital copy protection, is a topic that has been discussed more and more over recent years. In the case of protecting graphical content, often what you want the most is simply to prevent people from taking your images and using them as their own. To protect against redistribution, many online image galleries have taken to adding watermarkslogos or text that identify the owners of the contentto their images (see Figure 1-1). The watermark labels the owner of the content kind of like your mom writing your name on your underwear before you went to camp. If someone decides to take your image and host it on their site, they must cut out your watermark and leave an easily identifiable hole in the image. This hack will describe how to use the ImageMagick tool composite to add your own custom watermark to your image gallery. Before you watermark your images, you must first create the image you will use as a watermark. How the watermark is designed is mostly a matter of taste, but there are a few conventions you can use to make a good watermark:
Once your watermark has been created, the next step is to decide the ideal placement on your images. This can be tough. After all, images come in lots of shapes and sizes, andagainyou don't want to obscure a crucial part of the image. A common convention is to place watermarks near the bottom right-hand corner of an image. You could certainly place a watermark in the center of your image, but you run the chance of obscuring the part of the image people most want to see. composite has a number of advanced options, but for watermarking there are only a couple you absolutely need: -gravity and -watermark.The -gravity option defines a number of locations for a watermark. The supported locations are north, east, south, west, northeast, southeast, southwest, northwest, and center. The -watermark option takes as its argument a percentage that defines how translucent to make the watermark (which will determine how much your image will show through). To add a 35% translucent watermark in the bottom right-hand corner of an image (Figure 1-1), type: $ composite -watermark 35% -gravity southeast watermark.gif image.jpg \ image-watermarked.jpg In this example, watermark.gif is the watermark (with a transparent background), image.jpg is the image to watermark, and image-watermarked.jpg is the newly created combination of the two. Once you have created the image, view it to make sure that the transparency level is acceptable and the watermark is in the correct location.
Since this is a command-line program, it lends itself rather well to scripts. To add your watermark to all JPEG images in your current directory, type: $ for i in *.jpg; do j=`echo $i | sed -e 's/\.jpg/-wm.jpg/'`; \ composite -watermark 35% -gravity southeast watermark.gif $i $j; done; Figure 1-1. Image with a watermark in the bottom righthand cornerAll the watermarked images will have -wm added to the image name. To avoid accidentally renaming the files, you might want to store all your watermarked files in a separate directory. In that case, assuming the directory is called ~/watermarked, you would type: $ for i in *.jpg; do composite -watermark 35% -gravity southeast \ watermark.gif $i ~/watermarked/ $i; done; |