fix height, width in watermark code

Discussion in 'PHP' started by gspabla, Apr 21, 2009.

  1. #1
    hello frnds,
    im using below code to watermark my images
    <?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 = @imagecreatefrompng('watermark2.png');
    $imagewidth = imagesx($image);
    $imageheight = imagesy($image);  
    $watermarkwidth =  imagesx($watermark);
    $watermarkheight =  imagesy($watermark);
    $startwidth = (($imagewidth - $watermarkwidth)/1);
    $startheight = (($imageheight - $watermarkheight)/20);
    imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    ?>
    PHP:
    now i want fix height/width(say 100px) for the output image

    what and where to change in the code????
     
    gspabla, Apr 21, 2009 IP
  2. darren884

    darren884 Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change these 2:
    $watermarkwidth = 100;
    $watermarkheight = 100;
     
    darren884, Apr 21, 2009 IP