SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question fix height, width in watermark code

    hello frnds,
    im using below code to watermark my images
    PHP Code:
    <?php
    // this script creates a watermarked image from an image 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
    // 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$startheight00$watermarkwidth$watermarkheight);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    ?>
    now i want fix height/width(say 100px) for the output image

    what and where to change in the code????
    Edit/Delete Message

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will resize the entire image to 100px by 100px.

    PHP Code:
    $resized imagecreatetruecolor(100100);
    imagecopyresampled($resized$image0000100100$startWidth$startHeight);

    imagejpeg($resized); 
    Last edited by notepad_coder; Apr 22, 2009 at 18:23.
    - the lid is off the maple syrup again!

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by notepad_coder View Post
    This will resize the entire image to 100px by 100px.

    PHP Code:
    $resized imagecreatetruecolor(100100);
    imagecopyresampled($resized$image0000100100$startWidth$startHeight);

    imagejpg($resized); 
    where to put this code, i mean before/after which line?

  4. #4
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    // Replace this:
    imagejpeg($image);
    imagedestroy($image);

    // With this:
    $resized imagecreatetrucolor(100100);
    imagecopyresampled($resized$image0000100100$startWidth$startHeight);
    imagejpeg($resized);
    imagedestroy($image);
    imagedestroy($resized); 
    - the lid is off the maple syrup again!


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
  •