• Why png images have black background? Is any fix to this?

    Same problem with gif images with transparent background.

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • It’s probably a transparency/alpha channel issue.

    Try a 24 bit PNG* or an image without transparency/alpha

    *http://core.trac.wordpress.org/ticket/2805#comment:12

    Thread Starter chavo

    (@chavo)

    Hi. Thanks for your reply. I used a png-24 image with transparency. I need transparency/alpha channel.

    Thread Starter chavo

    (@chavo)

    Looking at the referred post and taking a look at the class-Category-Images-II.php file I think that the problem resides in how the plugin generates the thumbnail image:

    protected function save_thumb( $original_file, $thumb_file )
    	{
    		// Scale the image.
    		list( $w, $h, $format ) = getimagesize( $original_file );
    		$max_side = $this->get_max_side();
    		$xratio = $max_side / $w;
    		$yratio = $max_side / $h;
    		$ratio = min( $xratio, $yratio );
    		$targetw = (int) $w * $ratio;
    		$targeth = (int) $h * $ratio;
    
    		$src_gd = $this->image_create_from_file( $original_file );
    		assert( $src_gd );
    		$target_gd = imagecreatetruecolor( $targetw, $targeth );
    		imagecopyresampled ( $target_gd, $src_gd, 0, 0, 0, 0, $targetw, $targeth, $w, $h );
    		// create the initial copy from the original file
    		// also overwrite the filename (in case the extension isn't accurate)
    		$success = false;
    		if ( $format == IMAGETYPE_GIF ) {
    			$success = imagegif( $target_gd, $thumb_file );
    		} elseif ( $format == IMAGETYPE_JPEG ) {
    			$success = imagejpeg( $target_gd, $thumb_file, 90 );
    		} elseif ( $format == IMAGETYPE_PNG ) {
    			$success = imagepng( $target_gd, $thumb_file );
    		} else {
    			wp_die( __( 'Unknown image type. Please upload a JPEG, GIF or PNG.', 'category-images-ii' ) );
    		}
    		if ( ! $success )
    			wp_die( __( 'Image resizing failed.', 'category-images-ii' ) );
    	}

    Unfortunately, I’m not a code master to try to fix it. Any solve?

    ps: sorry for my english

    My mistake, I thought you were talking about core WP image resizing.

    You should contact the plugin author about a fix, looks like he’s actively working on it. This way everyone wins, and you can upgrade without worrying about breaking the change.

    The solution is outlined here:

    http://php.net/manual/en/function.imagecopyresampled.php#44134

    Thread Starter chavo

    (@chavo)

    Thanks madjax! I will take a look.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Png images with black background’ is closed to new replies.