Skip Menu |

This queue is for tickets about the GD CPAN distribution.

Report information
The Basics
Id: 40525
Status: rejected
Priority: 0/
Queue: GD

People
Owner: Nobody in particular
Requestors: BRUNORC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 2.39
  • 2.41
Fixed in: (no value)



Subject: "transparent" somehow alters color table
There is somehow strange behavior while applying transparency to images loaded from JPG/GIF files. To summarize: my $closest = $img->colorClosest( $r, $g, $b ); $img->transparent( $img->colorClosest( $r, $g, $b ) ); # Now $img->transparent == $closest # but $img->transparent != $img->colorClosest( $r, $g, $b ) I'm attaching the failing test.
Subject: transp.t
use strict; use warnings; use Test::More tests => 10; use_ok('GD'); my $im = GD::Image->newFromGif("class.gif"); $im->transparent( -1 ); is($im->transparent, -1, 'image is not transparent'); my $closest = $im->colorClosest( 24, 53, 62 ); $im->transparent( $im->colorClosest( 24, 53, 62 ) ); ok( $im->transparent == $closest, 'transparency preserves RGB before' ); ok( $im->transparent == $im->colorClosest( 24, 53, 62 ), 'transparency preserves RGB after' ); $im = GD::Image->newFromJpeg("class.jpg"); $im->transparent( -1 ); is($im->transparent, -1, 'image is not transparent'); $closest = $im->colorClosest( 24, 53, 62 ); $im->transparent( $im->colorClosest( 24, 53, 62 ) ); ok( $im->transparent == $closest, 'transparency preserves RGB before' ); ok( $im->transparent == $im->colorClosest( 24, 53, 62 ), 'transparency preserves RGB after' ); $im = GD::Image->newFromJpeg("dupa.jpg"); $im->transparent( -1 ); is($im->transparent, -1, 'image is not transparent'); $closest = $im->colorClosest( 24, 53, 62 ); $im->transparent( $im->colorClosest( 24, 53, 62 ) ); ok( $im->transparent == $closest, 'transparency preserves RGB before' ); ok( $im->transparent == $im->colorClosest( 24, 53, 62 ), 'transparency preserves RGB after' );
Yes, this is expected. It changes the alpha entry in the palette of either the given color or current transparent color. This is the logic in libgd for gdImageColorTransparent. if (!im->trueColor) { if((color < -1) || (color >= gdMaxColors)) { return; } if (im->transparent != -1) { im->alpha[im->transparent] = gdAlphaOpaque; } if (color != -1) { im->alpha[color] = gdAlphaTransparent; } } but colorClosest ignores the alpha, colorClosestAlpha would do it. change the sample to is( $im->transparent, $im->colorClosestAlpha( 24, 53, 62, 255 ), "ClosestAlpha" ); -- Reini Urban