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
    Moderator Array orlando's Avatar
    Join Date
    Sep 2008
    Posts
    111

    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 Array SticKer's Avatar
    Join Date
    May 2007
    Posts
    3,700

    Default Re: php script for create a watermark image.

    Thanks this will help protect images.

    SticKer

    Buy / Sell / Trade Products and Services at our Webmaster Marketplace

    61 Ways To Drive Targeted Traffic To Your Website

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

    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 Array
    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]
    [SIZE=3][FONT=Georgia]better Adsense CTR[/FONT][/SIZE]

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

    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 Array
    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.



Similar Threads

  1. Good Image Hosting Script?
    By Madinfo in forum Scripts & Content Management
    Replies: 1
    Last Post: 10-29-2008, 02:41 PM
  2. Image in folder background
    By sagar4evr in forum Tech Support
    Replies: 0
    Last Post: 06-02-2008, 03:41 AM
  3. Xml image rotator?
    By Appu s in forum Scripts & Content Management
    Replies: 1
    Last Post: 01-24-2008, 09:34 PM
  4. How to have image rss feeds on your website like yahoo?
    By sobe50418 in forum Scripts & Content Management
    Replies: 1
    Last Post: 01-12-2008, 12:19 AM

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
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |