www.webdeveloper.com
Results 1 to 2 of 2

Thread: watermarking image.

  1. #1
    Join Date
    Nov 2005
    Posts
    78

    watermarking image.

    I wrote a script this morning that watermarks JPG images that are uploaded using the imagecopymerge function. The watermark image is a PNG file created in Fireworks that has a transparent background color. The watermark is working, but the background is not a true transparent background, I have the int pct at 30 and it still showing up where I can see the watermark image as a square box. Here is part of my code

    PHP Code:
    $watermark imagecreatefrompng('ActIllWatermark.png');
    $watermark_width imagesx($watermark);
    $watermark_height imagesy($watermark);
    $image_h imagecreatefromjpeg($imagename);
    $size_x imagesx($image_h);  
    $size_y imagesy($image_h);  
    if(
    $watermark_height $size_y)
    {
        
    //Watermark is taller then image. lets scale it down to about 60%
        
    $watermark_height_temp $size_y 0.6;
        
    $diff $watermark_height $watermark_height_temp;
        
    $watermark_height $watermark_height_temp;
        
    $watermark_width $watermark_width $diff;
    }
    if(
    $watermark_width $size_x)
    {
        
    $watermark_width_temp $size_x 0.6;
        
    $diff $watermark_width $watermark_width_temp;
        
    $watermark_width $watermark_width_temp;
        
    $watermark_height $watermark_height $diff;
    }
    $dest_x = ($size_x 2) - ($watermark_width 2);
    $dest_y = ($size_y 2) - ($watermark_height 2);
    imagecopymerge($image_h$watermark$dest_x$dest_y00$watermark_width$watermark_height30);    
    imagejpeg($image_h$imagename); 
    Attached is an example of what the image is looking like after I watermark it, the character should be all 1 color black.

    Thanks for any help.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,739
    If you are copying a PNG with single channel transparency onto a jpeg use imagecopy(). For more info follow the link in my signature.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles