SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Watermark

  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Watermark

    I have a function that adds a watermark on a photo after it was uploaded and i don't understand why I can not apply the watermark:

    PHP Code:
    /********************/
        /*****WATERMARK*****/
        /********************/

            
    function doWatermark($calePoza$caleLogo$pozitionare 'centru') {
              
    $watermark imagecreatefrompng($caleLogo);
             

              
    $filetype substr($calePoza,strlen($calePoza)-4,4);
              
    $filetype strtolower($filetype);

              if(
    $filetype == ".gif")  {$photo imagecreatefromgif($calePoza);}
              if(
    $filetype == ".jpg")  {$photo imagecreatefromjpeg($calePoza);}
              if(
    $filetype == "jpeg") {$photo imagecreatefromjpeg($calePoza);}
              if(
    $filetype == ".png")  {$photo imagecreatefrompng($calePoza);}


              
    imagealphablending($phototrue);
             
              
    $widthWatermark imagesx($watermark);
              
    $heightWatermark imagesy($watermark);
              
    $widthPhoto imagesx($photo);
              
    $heightPhoto imagesy($photo);
              if (
    $pozitionare == 'centru') {
                  
    $xLogoPosition ceil(($widthPhoto $widthWatermark) / 2);
                  
    $yLogoPosition ceil(($heightPhoto $heightWatermark) / 2);
              } else {     
                  
    $xLogoPosition $widthPhoto $widthWatermark 10;
                  
    $yLogoPosition $heightPhoto $heightWatermark 10;
              }
             
              
    $result imagecopy($photo$watermark$xLogoPosition$yLogoPosition00$widthWatermark$heightWatermark);
             

              if(
    $filetype == ".gif")  {header('Content-type: image/gif');imagegif($photo$calePoza100); }
              if(
    $filetype == "jpeg") {header('Content-type: image/jpeg');imagejpeg($photo$calePoza100);}
              if(
    $filetype == ".jpg")  {header('Content-type: image/jpeg');imagejpeg($photo$calePoza100);}
              if(
    $filetype == ".png")  {header('Content-type: image/png');imagepng($photo$calePoza100);}

              
    imagedestroy($photo);

              return 
    $result;
           } 

  2. #2
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PS: if i delete :

    PHP Code:
     if($filetype == ".gif")  {$photo imagecreatefromgif($calePoza);}

              if(
    $filetype == ".jpg")  {$photo imagecreatefromjpeg($calePoza);}

              if(
    $filetype == "jpeg") {$photo imagecreatefromjpeg($calePoza);}

              if(
    $filetype == ".png")  {$photo imagecreatefrompng($calePoza);} 
    and replace it with :

    PHP Code:
    $photo imagecreatefromjpeg($calePoza); 

    and this :

    PHP Code:
     if($filetype == ".gif")  {header('Content-type: image/gif');imagegif($photo$calePoza100); }

              if(
    $filetype == "jpeg") {header('Content-type: image/jpeg');imagejpeg($photo$calePoza100);}

              if(
    $filetype == ".jpg")  {header('Content-type: image/jpeg');imagejpeg($photo$calePoza100);}

              if(
    $filetype == ".png")  {header('Content-type: image/png');imagepng($photo$calePoza100);} 
    with this :
    PHP Code:
    imagejpeg($photo$calePoza100); 
    everything works fine, but only with .jpeg files.


Tags for this Thread

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
  •