SitePoint Sponsor

User Tag List

Page 1 of 6 12345 ... LastLast
Results 1 to 25 of 138
  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Article Discussion

    This is an article discussion thread for discussing the SitePoint article, "Watermark Images on the Fly in PHP"

  2. #2
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two words: YOU ROCK!

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Two words: Thank you
    Brock Ferguson
    Lead Developer, Caribou CMS
    A Subscription/Membership CMS and Ecommerce Platform - FREE Trial

  4. #4
    Web Design Ireland cianuro's Avatar
    Join Date
    Jun 2004
    Location
    Dublin Ireland
    Posts
    914
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is one of the best articles I have read in watermarking. Excellent resource. Thank you very much.

  5. #5
    powlow
    SitePoint Community Guest
    its not that amazing! :)
    great article...also interesting to try with TTF fonts for dynamic text.

  6. #6
    Taz
    SitePoint Community Guest
    Can anyone that has had success with the above please advise what version of GD and what version of libpng you are running..?

    Great tutorial btw, shame i cant get it working because my version of libpng is incompattible.

    Thanks

  7. #7
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Reston
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For larger or more heavily trafficked sites, I imagine this could begin to take a toll on performance if a watermarked image is reassembled every time it's requested.

    The next step for this script would be to write the assembled image to a cache directory, similar to how some weblog apps write static copies of their entries. Could be called as a cron job or upon uploading a new image or etc...

    Nice script, I'd been contemplating doing something like this both for watermarks and borders.

  8. #8
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is great, but I have a question.

    I would like to use a png with a transparent bg as my watermark image, but the result is black pixels where the watermark's transparency should be. Is this a feature of my version of GD/PHP/whatever, or is it a limitation of the basic script source (as supplied)?

    TIA
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  9. #9
    SitePoint Enthusiast vek's Avatar
    Join Date
    Jun 2004
    Location
    Florence, KY
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chillijam
    This is great, but I have a question.

    I would like to use a png with a transparent bg as my watermark image, but the result is black pixels where the watermark's transparency should be. Is this a feature of my version of GD/PHP/whatever, or is it a limitation of the basic script source (as supplied)?

    TIA
    Maybe try
    PHP Code:
    <?php  

    header
    ('content-type: image/jpeg');  

    $watermark imagecreatefrompng('watermark.png');  
    $imgtran imagecolorallocate($image000); //whatever the rgb transparent color is
    imagecolortransparent($watermark$imgtran); //make that color transparent
    $watermark_width imagesx($watermark);  
    $watermark_height imagesy($watermark);  
    $image imagecreatetruecolor($watermark_width$watermark_height);  
    //$image = imagecreatefromjpeg($_GET['src']);  
    $image imagecreatefrompng($_GET['src']);
    $size getimagesize($_GET['src']);  
    $dest_x $size[0] - $watermark_width 5;  
    $dest_y $size[1] - $watermark_height 5;  
    imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);
    imagetruecolortopalette($imagetrue256); //use this to force 256 bit transparent pngs to show up in IE.
    //imagejpeg($image);  
    imagepng($image);
    imagedestroy($image);  
    imagedestroy($watermark);  

    ?>

  10. #10
    circus
    SitePoint Community Guest
    if your getting black pixel you need php 4.3.3 at least for gd 2

  11. #11
    paul
    SitePoint Community Guest
    Hi Brock,
    great article, but I was not able to get it to work. Bear with me as I am not very knowlagble with php..

    but from your article, I assume we have to save the script (e.g. image.php) and then call the image to be watermarked as image.php?image=pic.jpg

    but when i do this i get this error:

    <br />
    <b>Warning</b>: imagecopymerge(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>13</b><br />
    <br />
    <b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>14</b><br />
    <br />
    <b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/httpd/vhosts/domain.com/httpdocs/image.php</b> on line <b>15</b><br />


    all the files are in the same folder. Any idea what i am doing wrong?

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The default way the script works is by giving the $_GET['src'] variable (?src=value] with value being the complete path to the file (/home/user/public_html/images/file.jpg for example).

  13. #13
    SitePoint Member
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, I just thinking about watermarking some images of my site that are getting heavily linked to, and voila, where's a quick script.

    But this is just a first step. What I really want to do, is develop this script so that it looks at the requests and determines is it from somewhere outside the website? Or is from within? Referrer value is what I want know.

    If it's from within, I would rather not "stain" the pictures with my "url" and copy write information. But if it's an external link, well, I'd like to at least let them know from where the picture their viewing, came from.

    Any thoughts on this?

    Thanx

  14. #14
    SitePoint Member SlappyAss's Avatar
    Join Date
    Aug 2004
    Location
    Bliss
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In The PHP Anthology, HarryF deals with the hot-linking issue using sessions. Good book and base classes to build on, if you do the whole oop php thing. Still having trouble with 5 though (install that is).

    I have used this class as a base to what i ended up making an overly robust thumbnail generation monstrosity....but it was fun.

  15. #15
    JoeB
    SitePoint Community Guest
    In your code:

    $image = imagecreatetruecolor($watermark_width, $watermark_height);

    $image = imagecreatefromjpeg($_GET['src']);


    Why are you doing both these lines one after the other? Isn't that just a waist of CPU time as the $image created in the 1st line is overwritten by the next call?


  16. #16
    SitePoint Member sseiter's Avatar
    Join Date
    Sep 2004
    Location
    Cincinnati, Ohio
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works all fine and dandy, but why doesn't it work when you use it in a html table?

  17. #17
    Lethargic
    SitePoint Community Guest
    Why does everyone always use pngs in these tutorials, why would I want to use that format when every image I have is either a jpeg or gif! My digital camera only outputs jpeg..... just some food for thought

  18. #18
    SitePoint Member sseiter's Avatar
    Join Date
    Sep 2004
    Location
    Cincinnati, Ohio
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    You can use jpegs to create images on the fly. The png is only used as the watermark on your image. This is generally due to the transparent background. This looks nice on images

  19. #19
    jason
    SitePoint Community Guest
    This script actually doesn't work for me. I'm not sure if Photoshop created .png files have terrible transparency or what, but the watermark uses white where it should be transparent. I have GD2.0+. Any suggestions?

  20. #20
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great Article. I love the ability to watermark in PHP. I have been using it for a while now. Works great! Here is an example of the output is creates:

    The logo and Copyright info is the Watermark.
    .:Blog:.

  21. #21
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DocDave,

    Any chance you could post the code you actually use, please? I still haven't managed to sort out my issues, mainly because I have very little time to do it.

    TIA
    CJ
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  22. #22
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok here you go, the variable $photo_file is the file that was uploaded earlier in the routine. There is other stuff in the routine to size the image and what not. Hope this helps.
    PHP Code:
    // Get the uploaded photos dimensions
    $photo_size getimagesize($photo_file);
    $photo_width $photo_size[0];
    $photo_height $photo_size[1];

    // Create an image from the uploaded jpg
    $photo_image imagecreatefromjpeg($photo_file);
                
    // Turn on Alpha Blending for the uploaded jpg
    ImageAlphaBlending($photo_imagetrue);
                
    // Check that the uploaded photo's width is larger than the 
    // requested fullsize photo width, otherwise use the original width
    if ($photo_width $INFO['max_img_width'])
    {
            
    $pic_width $INFO['max_img_width'];
    }
    else
    {
            
    $pic_width $photo_width;
    }
                
    // Calculate the the fullsize photo height based on the width
    $pic_height round($photo_height / ($photo_width $pic_width));
                
    // Create the new image
    $pic_img imagecreatetruecolor($pic_width,$pic_height);
                
    imagecopyresized($pic_img,$photo_image,0,0,0,0,$pic_width,$pic_height,$photo_width,$photo_height);
                
    // Define the watermark png file
    $logo_file $INFO['server_path']."/".$INFO['gallery_dir']."/htm/watermark.png";
                
    // Get the logo dimensions from the file
    $logo_size getimagesize($logo_file);
    $logo_width $logo_size[0];
    $logo_height $logo_size[1];
                
    // Create an image from the watermark png file
    $logo_image ImageCreateFromPNG($logo_file);
                
    // Copy watermark logo image onto the photo image
    ImageCopy($pic_img$logo_image$INFO['mark_x'], $INFO['mark_y'], 00$logo_width$logo_height);

    // Define the location of the jpg file to be created
    $pic_file $INFO['server_path']."/".$INFO['gallery_dir']."/pic/".$save_as_name;
                
    // Create and store a jpg at the fullsize pic quality from the resized image created
    imagejpeg($pic_img$pic_file$INFO['img_quality']);

    // Clean-up any other left over images
    ImageDestroy($photo_image);
    ImageDestroy($logo_image);
    ImageDestroy($pic_img); 
    .:Blog:.

  23. #23
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfection! Thanks Dave
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  24. #24
    Pascal
    SitePoint Community Guest
    I'm stuck with the following issue:

    I've got two servers, one (free of cost) server containing some image archives (from now on referred to as server 1). This server does not run PHP and all access I have to that server is an FTP login. The other server (from now on referred to as server 2) is a true web server with PHP installed, and this one costs money.

    So now I want to watermark the images from my PHP-less server 1 and show them on my site on server 2 (which does have PHP), WITHOUT using the bandwith of server 2, since then it will cost money you see ;)

    I'm thinking about this for some time now and I guess what I want is impossible. Can anyone confirm that?

    Please send a mail to alpha@zoepe.nl -> thank you!

  25. #25
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought that I was a decent PHP programmer, yet I can't get this bloody thing to generate anything but errors. I've got like 200 pictures to watermark, I'll be doing it for a while, unless one of you dudes can make sence of this.

    I screwed with it for a while longer... and now I have white where it should be clear. I seem to remember someone with the same type of problem but with black... I'll have to refer back in the thread.

    Keep ya posted. ;)

    [edit: now its black too lol I might have to try and use DocDaves script and see what comes of it]


Bookmarks

Posting Permissions

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