Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Black images when using image class for image processing
  • When I am uploading an image I use Image class to resize original photo to several dimensions and save each image variation to separate file. Now I got request to put a watermark on images. Everything is simple and fine using Image::watermark() method, but I run into some problems. My image processing goes like this: 1. grab and load the uploaded photo
    2. put the watermark on this photo
    3. crop and resize watermarked photo to desired new dimension(s) and save to file(s) My code is:
    //if watermark checked then add watermark to original uploaded photo and overwrite it
    if($watermark=="true") 
    {
        Image::load($file)
             ->config('quality', 100)
             ->watermark(DOCROOT.'assets/img/logofoot.png', 'top left', 20)
             ->save($file);
    }
    
    //create 3 different image sizes from watermarked photo
    Image::load($file)
                ->config('quality', 100)
                ->crop_resize($neww1, $newh1)
                ->save($uploaddir . DIRECTORY_SEPARATOR . $newname1);
    Image::load($file)
                ->config('quality', 100)
                ->crop_resize($neww2, $newh2)
                ->save($uploaddir . DIRECTORY_SEPARATOR . $newname2);
    Image::load($file)
                ->config('quality', 100)
                ->crop_resize($neww3, $newh3)
                ->save($uploaddir . DIRECTORY_SEPARATOR . $newname3);
    

    This works, but sometimes I get black images when crop/resizing watermarked image into smaller dimensions. Not always but only sometimes. The original watermarked photo is fine, but smaller versions I create afterwards are black... Why is this happening? If I skip watermarking uploaded image (first if clause) then everything is fine, no black images! Thanks,
    Jume
  • This can happen when using GD if you have an indexed-colored PNG image instead of a true-color image with an alpha channel, and you combine it with an image that has transparency. So the problem is in the original image. I don't know enough about the Image class to say if that has the option to detect the color type, and to convert from indexed to true-color, before you apply the watermark.
  • Hmmm are you sure? Checked one of the cases and the original image is standard JPEG. The watermark image is ofcourse transparent PNG.
  • Actually I just figured out this only happens when my original image is JPEG. If its an PNG then its ok.
    This can happen when using GD if you have an indexed-colored PNG image instead of a true-color image with an alpha channel, and you combine it with an image that has transparency. So the problem is in the original image. I don't know enough about the Image class to say if that has the option to detect the color type, and to convert from indexed to true-color, before you apply the watermark.

    The problem is than only resized images are blank, the watermarked image is ok no matter what the source image is... which is very funny! How should I solve this ? thanks,
    Jume

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion