WordPress.org

Forums

Taxonomy Images II
Png images with black background (6 posts)

  1. chavo
    Member
    Posted 3 years ago #

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

    Same problem with gif images with transparent background.

    Thanks in advance.

  2. Jackson
    Member
    Posted 3 years ago #

    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

  3. chavo
    Member
    Posted 3 years ago #

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

  4. chavo
    Member
    Posted 3 years ago #

    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

  5. Jackson
    Member
    Posted 3 years ago #

    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

  6. chavo
    Member
    Posted 3 years ago #

    Thanks madjax! I will take a look.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Taxonomy Images II
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic