Background transparency problem in NextGen Gallery thumbnails

Featured Image

For some time I didn't keep my post thumbnails in NextGen Gallery. On this website they are all PNG images with a transparent background. The thumbnails created by NextGen were losing background transparency and their background was black. It was unacceptable because of theme switching. My themes use different backgrounds and thumbnails looked rather ugly. Finally I found this post: ...plugin-nextgen-gallery-problems-with-png-transparency-thumbnails which offered a solution. It requires a modification of NextGen plugin code and after every upgrade of NextGen you'll have to remember to re-apply this patch.

The solution: in nextgen-gallery/lib/gd.thumbnail.inc.php file find the function fastimagecopyresampled and replace it with the following code:

function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 5) {
    $dst_img = imagecreatetruecolor($dst_w, $dst_h);
    imagealphablending($dst_image, false);
    imagesavealpha($dst_image,true);
    $transparent = imagecolorallocatealpha($dst_image, 255, 255, 255, 127);
    imagefilledrectangle($dst_image, 0, 0, $dst_w, $dst_h, $transparent);
    imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    return true;
}

It works for me. I hope it'll work for you as well.

Leave a Reply

Links are not allowed in comment field!

Your email address will not be published. Required fields are marked *