Watermarking Images with transparent text

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Watermarking Images with transparent text

Post by AGISB »

Hi, I like to accomplish the following: I have a members sections with pictures and to prevent the people to publish the pictures I like to watermark them on the fly with their username using a somewhat transparent approach to the text so it is not completely disturbing.

I searched here and I searched google but it seems I cannot find any working solution to this. I would not like to create transparent pngs for all letters capital and small and all numbers to place images on the picture.

Is there any way, I can accomplish to place semi-transparent Text on an image just using gd funtions?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Re: Watermarking Images with transparent text

Post by AGISB »

Got it myself. Just my solution for future reverence:

Code: Select all

              $text = "Some Text";
              $the_image = imagecreatefromjpeg("path_to_pic");
              $stamp = imagecreatetruecolor(260, 18);
              imagesavealpha($stamp, true);
              $white = imagecolorallocate($stamp, 255, 255, 255);
              $grey = imagecolorallocate($stamp, 128, 128, 128);
              $black = imagecolorallocate($stamp, 0, 0, 0);
              $trans_colour = imagecolortransparent($stamp, $white);
              imagefill($stamp, 0, 0, $trans_colour);
              imagestring($stamp, 5, 0, 0, $text, $grey);
              $marge_right = 0;
              $marge_bottom = 0;
              $sx = imagesx($stamp);
              $sy = imagesy($stamp);
              imagecopymerge($the_image, $stamp, imagesx($the_image) - $sx - $marge_right, imagesy($the_image) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 60);
Now I will add a custom Font and all is fine ;)
Post Reply