Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Image Automatic Watermarking.

  1. #1
    Join Date
    Jan 2007
    Location
    Bournemouth, England
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Image Automatic Watermarking.

    Hi, Does anyone know of any free Automatic image watermarking that I can implement into a image uploading script.

    Thanks.

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Use CSS:
    Code:
    background:url('myimage.jpg') no-repeat fixed top left;
    If you want to give it a "watermark" effect, use an image-editing program.
    - Mike

  3. #3
    Join Date
    Jan 2007
    Location
    Bournemouth, England
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for quick reply but is it possible for PHP to get an image, put a watermark over it so its only one image. I think it is because PHP can create captcha codes on the fly.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Look in the php.net manual (image functions):
    http://ca3.php.net/manual/en/ref.image.php
    - Mike

  5. #5
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You should be able to combine two images fairly easily.

    Create a loop that runs through all of the pixels, then for each that is white in the watermark image, make the pixel of the main image a blend of the watermark pixel and image pixel. If black, leave as is. Or any variation you want.


    Basically, something like--

    PHP Code:
    <?php
    $imgurl 
    $_GET['img'];
    $image=imageCreateFromJPEG($imgurl);
    //or create your image from upload

    $imagewidth imagesx($image);
    $imageheight imagesy($image);
    //get dimensions

    $watermarkurl $_GET['wm'];
    $watermark=imageCreateFromGIF($watermarkurl);
    //as above, do what you want for getting the watermark

    $wmwidth imagesx($watermark);
    $wmheight imagesy($watermark);
    //get dimensions of watermark

    imagecopyresampled($watermark$watermark0000$imagewidth$imageheight$wmwidth$wmheight);
    //resize the watermark to be in the same dimensions as the image

    for ($y 0$y $imageheight$y++) {
        for (
    $x 0$x $imagewidth$x++) {
            
    $imgcolor imagecolorat($image,$x,$y);
            
    $imgcolorrgb imagecolorsforindex($image,$imgcolor);
            
    $ir $imgcolorrgb['red'];
            
    $ig $imgcolorrgb['green'];
            
    $ib $imgcolorrgb['blue'];
            
    $wmcolor imagecolorat($watermark,$x,$y);
            
    $wmcolorrgb imagecolorsforindex($watermark,$wmcolor);
            
    $wr $wmcolorrgb['red'];
            
    $wg $wmcolorrgb['green'];
            
    $wb $wmcolorrgb['blue'];
            if (
    $ir<$wr&&$ig<$wg&&$ib<$wb) {
                
    $pxcolor imagecolorallocate($image, ($ir+$wr)/2, ($ig+$wg)/2, ($ib+$wb)/2);
                
    imagesetpixel($image$x$y$pxcolor);
            }
        }
    }
    //loop through image
    //and set pixel to white
    //if wm is white at pixel

    header("Content-type: image/jpg");
    imagejpeg($image);
    imagedestroy($image);
    //output
    ?>
    Last edited by djr33; 03-19-2007 at 11:52 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Does gd library support layers?

    if so, a semitransperent png ontop of the watermarked picture would be the best option.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Its support for layers is annoying and not very trustworthy.

    Anyway, I've been testing, and here's the result:

    http://ci-pro.com/misc/phptest/image...er/Image25.gif
    From two random sources:
    http://www.huddletogether.com/projec...es/image-1.jpg
    http://www.informika.ru/text/magaz/higher/Image25.gif

    Note: The code in the last post is updated to reflect changes I made.
    Last edited by djr33; 03-19-2007 at 11:52 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    It's a bit laggy though.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sure. It's running through every pixel.

    This is for watermarking on upload, so it shouldn't be an issue.

    Write a faster script if you question this
    ...PHP is slow with images, but I have yet to find a way around that.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •