Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    247
    Thanks
    13
    Thanked 26 Times in 24 Posts

    GD: Watermark not working.

    It creates and converts images to jpg like it should but the watermark doesn't work. And the path to the watermark is correct; I checked it like 3 times. Anyway, here's the PHP:

    PHP Code:
    function makeimage($image$watermark)
    {
        
    $img_explode explode('.'$image);
        
    $img_ext $img_explode[1];

        
    // create new image
        
    switch ($img_ext
        {
            case 
    'gif':
                
    $new_image = @imagecreatefromgif($image);
                break;

            case 
    'jpg':
                
    $new_image = @imagecreatefromjpeg($image);
                break;

            case 
    'jpeg':
                
    $new_image = @imagecreatefromjpeg($image);
                break;

            case 
    'png':
                
    $new_image = @imagecreatefrompng($image);
                break;
        }

        
    $watermark_width imagesx($watermark);  
        
    $watermark_height imagesy($watermark);

        
    $size getimagesize($image);

        
    $dest_x $size[0] - $watermark_width 5;  
        
    $dest_y $size[1] - $watermark_height 5;

        
    // merge watermark and image
        
    imagecopymerge($new_image$watermark$dest_x$dest_y00$watermark_width$watermark_height100);

        
    imagedestroy($watermark);

        return 
    $new_image
    }

    header("Content-Type: image/jpeg");

    $dir $_SERVER['DOCUMENT_ROOT'];
    $imagedir $dir."/img/gallery/";
    $watermark $dir."/img/watermark.png";

    $imagename $_FILES['image']['name'];
    $imagepath $imagedir.$imagename;

    move_uploaded_file($_FILES['image']['tmp_name'], $imagepath) or die("Unable to upload.");

    $imagenewname "img".rand(1,999999).".jpg";
    $imagenewpath $imagedir.$imagenewname;

    rename($imagepath$imagenewpath);
    unlink($imagepath);

    // make image
    $image makeimage($imagenewpath$watermark);
    imagejpeg($image); 
    Thanks in advance.
    Last edited by Majoracle; 11-16-2007 at 09:23 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •