Results 1 to 6 of 6

php script for create a watermark image.

This is a discussion on php script for create a watermark image. within the Programming forums, part of the Web Designing & Development category; Hi I found this article when i stumbling. And i think this is informative for all of you friends. List ...

  1. #1
    Senior Member orlando's Avatar
    Join Date
    Sep 2008
    Posts
    113

    Default php script for create a watermark image.

    Hi

    I found this article when i stumbling. And i think this is informative for all of you friends.

    List of things needed:
    1. your image in any format
    2. watermark image--in gif format with transparent background
    3. script below with name (i.e. watermark.php)

    code

    <?php
    // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
    // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
    // where this script is named watermark.php
    // call this script with an image tag
    // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
    $imagesource = $_GET['path'];
    $filetype = substr($imagesource,strlen($imagesource)-4,4);
    $filetype = strtolower($filetype);
    if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
    if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
    if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
    if (!$image) die();
    $watermark = @imagecreatefromgif('watermark.gif');
    $imagewidth = imagesx($image);
    $imageheight = imagesy($image);
    $watermarkwidth = imagesx($watermark);
    $watermarkheight = imagesy($watermark);
    $startwidth = (($imagewidth - $watermarkwidth)/2);
    $startheight = (($imageheight - $watermarkheight)/2);
    imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    ?>
    Name this script, i.e. watermark.php and call this script as following:
    HTML
    <img src="watermark.php?path=image_name.filetype">
    the only thing you need to chage is "image_name.filetype" and of course you can have the relative path such as:
    HTML
    <img src="folder/watermark.php?path=folder/imagename">

    The caution here is the script watermark.php and watermark.gif should be in the same location. watermark.gif should have transparent background.

    As you can read it from the site, the location where the watermark.gif appears can be modified by adjusting this line of the code:
    CODE
    $startwidth = (($imagewidth - $watermarkwidth)/2);
    $startheight = (($imageheight - $watermarkheight)/2);
    To have it appear on the bottom right corner, try this:
    CODE
    $startwidth = (($imagewidth - $watermarkwidth) );
    $startheight = (($imageheight - $watermarkheight) );
    thanks

  2. #2
    Administrator SticKer's Avatar
    Join Date
    May 2007
    Posts
    4,261
    Blog Entries
    24

    Default Re: php script for create a watermark image.

    Thanks this will help protect images.

    SticKer

  3. #3
    Senior Member akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    504

    Default Re: php script for create a watermark image.

    thanks a lot.
    it is very useful to protect image.
    thanks again.

  4. #4
    Junior Member
    Join Date
    Dec 2008
    Posts
    2

    Default Re: php script for create a watermark image.

    [SIZE=3][FONT=Franklin Gothic Medium]Well thanks a lot for that piece ov code,i too was searchin for it


    [/FONT][/SIZE]

  5. #5
    Senior Member akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    504

    Default Re: php script for create a watermark image.

    I have find it here also. check it.
    http://www.phpjabbers.com/put-waterm...php-php20.html

  6. #6
    Senior Member
    Join Date
    Mar 2011
    Posts
    194

    Default Re: php script for create a watermark image.

    It is a right code for protect image and the links are very useful,thanks a lot.