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 Image Library and gif issues.

    I have an image uploading thing that creates an images from gif, png, and jpg (jpeg), creates a thumbnail from the created image (jpg), and then watermarks the created image, then saves as jpg. All that works just fine, except when the original images are gif.

    For images that were originally gif; the watermark only shows as a white block where the watermark should be (the watermark is a transparent png image). Then there's transparent gifs. The transparency fills with white, but when the thumbnail is created, the transparency fills with black. Anyway I can have the thumbnail fill with white like the original? For animated gifs, it takes the first image in the loop and converts it to the jpg (no surprise here, considering jpg can't be animated). I get the same white block watermark though.

    How do I fix these problems, if I can?

    Code:
    PHP Code:
    $dir $_SERVER['DOCUMENT_ROOT'];
        
    $imagedir $dir."/img/gallery/";
    $image str_replace(array(" ""/"".."), ""strtolower($_FILES['image']['name']));
    $imagepath $imagedir.$image;

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

    $img_explode explode('.'$image);
    $img_ext $img_explode[1];
    switch (
    $img_ext)
    {
        case 
    'jpg': case 'jpeg':
            
    $new_image imagecreatefromjpeg($imagepath);
            break;

        case 
    'png':
            
    $new_image imagecreatefrompng($imagepath);
            break;

        case 
    'gif':
            
    $new_image imagecreatefromgif($imagepath);
            break;

        default: die(
    'Unknown file type error.');
    }
        
    $image_width imagesx($new_image);
    $image_height imagesy($new_image);
        
    $imagenewname "img".rand(1000000,9999999);
    $imagenewpath $imagedir.$imagenewname.".jpg";

    // start thumbnail creation process
    $thumbdir $imagedir."thumbs/";
        
    $ratio = ($image_width $image_height) ? (150 $image_width) : (150 $image_height);
    $th_width $image_width $ratio;
    $th_height $image_height $ratio;

    $thumb imagecreatetruecolor($th_width$th_height);
    imageantialias($thumbtrue);
        
    $thumbpath $thumbdir.$imagenewname.".jpg";
    imagecopyresampled($thumb$new_image0000$th_width$th_height$image_width$image_height);
    imagejpeg($thumb$thumbpath100);
        
    imagedestroy($thumb);
    // end thumbnail creation process

    // start watermarking process
    $wm $dir."/img/watermark.png";

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

    imagealphablending($new_imagetrue);
    imagealphablending($watermarktrue);

    imagecopy($new_image$watermark, ($image_width $watermark_width 5), ($image_height $watermark_height 5), 00$watermark_width$watermark_height);
    imagejpeg($new_image$imagenewpath);

    imagedestroy($watermark);
    // end watermarking process

    imagedestroy($new_image);
    unlink($imagepath); 
    Last edited by Majoracle; 11-18-2007 at 01:57 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
  •