#! /usr/bin/perl -w # # $Id$ # Copyright (c) 2007 patrick keshishian use strict; use GD; # global vars my $self = `basename $0`; chomp($self); # proto-sub sub main(); # main main(); exit(0); # subs sub main() { my ($wm_file, $src_file, $out_file); my ($iw, $is, $io); my $percent = 55.0; # transparency # set-up $wm_file = 'circ.png'; $src_file = 'test_in.jpg'; $out_file = sprintf('test_out_v1_%.1f.jpg', $percent); GD::Image->trueColor(1); # open source image $is = GD::Image->new($src_file) or die(sprintf("Failed to open \"%s\"", $src_file)); # open watermark image $iw = GD::Image->new($wm_file) or die(sprintf("Failed to open \"%s\"", $wm_file)); printf("iw->trueColor() = %d$/", $iw->trueColor()); printf("is->trueColor() = %d$/", $is->trueColor()); # # Copy watermark onto source image using GD::Image->copyMerge(), # similar to GD::Image->copy() but with one extra argument specifying # extent to which the colours of the two images are to be merged. # At first sight, this function is misleading, giving one the (or # at least to me) that GD would do proper alpha-blending. # Not so. The actually comment for the GD's C library function, # gdImageCopyMerge() reads: # # /* This function is a substitute for real alpha channel operations, # so it doesn't pay attention to the alpha channel. */ # $is->copyMerge($iw, 50, 50, 0, 0, $iw->width, $iw->height, $percent); # open destination/out file for writing open(OUT, ">$out_file") or die(sprintf("Failed to write \"%s\": %s", $out_file, $!)); # write out resulting image print(OUT $is->jpeg(70)); close(OUT); exit(0); }