I have a few website that I’ve designed in WordPress using a shopping cart plugin, and then trained the owner how to insert new products along with images of the products. After the client uploaded a hundred or so products we found that all the thumbnails WordPress automatically generated had black backgrounds. All of the client’s images were gifs. Here’s a quick fix:
Step 1 – Edit WordPress media.php
Edit the WordPress file /wp-includes/media.php and edit starting on line 422:
$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
if(IMAGETYPE_GIF == $orig_type){
$black=imagecolorallocate($image, 0,0,0);
imagecolortransparent($image, $black);
}
imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
This doesn’t preserve the tranparency, but sets the black background in the image to transparent just before the thumbnail is created. FYI, this will most likely be overwritten next time you update WordPress.
Step 2 – Regenerate Thumbnails
Step 1 only covers thumbnails that will be created in the future, so we need to regenerate the thumbnails. Luckily, you don’t have to do all of this manually, you can install the Regenerate Thumbnails plugin. Once you run that plugin, all your thumbnails should be fixed!