Jump to content

Watermark images


fone337

Recommended Posts

Hi, quite new to PHP and been building an image gallery based on one I found at php-mysql-tutorial.com which is great!

My problem is I'd like to watermark the images that get uploaded! I've tried a few things but no luck, closest I got was it uploading just a black image at the right dimensions? The original upload script is below, any help would be massively appreciated. Thanks in advance.

 

function copyImage($srcFile, $destFile, $w, $h, $quality = 75)

{

    $tmpSrc    = pathinfo(strtolower($srcFile));

    $tmpDest    = pathinfo(strtolower($destFile));

    $size      = getimagesize($srcFile);

 

    if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")

    {

      $destFile  = substr_replace($destFile, 'jpg', -3);

      $dest      = imagecreatetruecolor($w, $h);

      imageantialias($dest, TRUE);

    } elseif ($tmpDest['extension'] == "png") {

      $dest = imagecreatetruecolor($w, $h);

      imageantialias($dest, TRUE);

    } else {

      return false;

    }

 

    switch($size[2])

    {

      case 1:      //GIF

          $src = imagecreatefromgif($srcFile);

          break;

      case 2:      //JPEG

          $src = imagecreatefromjpeg($srcFile);

          break;

      case 3:      //PNG

          $src = imagecreatefrompng($srcFile);

          break;

      default:

          return false;

          break;

    }

 

    imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);

 

    switch($size[2])

    {

      case 1:

      case 2:

          imagejpeg($dest,$destFile, $quality);

          break;

      case 3:

          imagepng($dest,$destFile);

    }

    return $destFile;

 

}

Link to comment
https://forums.phpfreaks.com/topic/76369-watermark-images/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.