On Wed, 2003-06-18 at 13:08, John Sequeira wrote:
> I'm working on a web site that would like to change their color scheme.
> They have about a thousand images (buttons/widgets/etc) and I was
> wondering if there was a easy way to do this programmatically or at
> least give the manual process a big head start.
GD is slow for such manipulations because it has to read in the entire
image, manipulate the global color table, then write the whole thing
back.
If you're going for speed, and are manipulating GIF images, the
following might be useful; it takes the path to a GIF image, and a set
of old => new hex codes, and returns the transformed image, ripe for
outputting to a file. I've used this quite a bit from TT2 code in the
past.
- Alex
sub giftrans {
my ($image, %mapping) = @_;
local $/ = undef;
open GIF, $image or die "Can't open $image: $!";
my $gif = <GIF>;
close GIF;
my $depth = 2 << (vec($gif,10,8) & 0x7);
for my $i (1 .. $depth) {
my $key = sprintf "#%02x%02x%02x",
vec($gif,10+$i*3,8),
vec($gif,11+$i*3,8),
vec($gif,12+$i*3,8);
if (exists $mapping{$key}) {
my @c = map {hex $_} $mapping{$key} =~ /\#(..)(..)(..)/;
my $j = 10+$i*3;
vec($gif, 10+$i*3+$_, 8) = shift @c
for 0..2;
}
}
return $gif;
}
--
Networking -- only one letter away from not working.
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm