Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Imager to generate thumbnails and center them on a background. When I create a new image with Imager->new how do I tell it to make the background transparent (or even white) instead of black?
  • Comment on Imager transparent background instead of black

Replies are listed 'Best First'.
Re: Imager transparent background instead of black
by Khen1950fx (Canon) on Nov 11, 2010 at 03:16 UTC
    I'd use Imager::Fill.
    #!/usr/bin/perl use strict; use warnings; use Imager; use Imager::Fill; my $fill = Imager::Fill->new(type => "opacity", other => $fill, opacity => 0.25);
    where $fill is The Imager::Fill object you want to modify, and the default opacity is 0.5. You can modify the opacity to get the level of tranparency that you want.
Re: Imager transparent background instead of black
by Anonymous Monk on Nov 10, 2010 at 19:12 UTC
Re: Imager transparent background instead of black
by tonyc (Hermit) on Nov 22, 2010 at 00:12 UTC

    By default Imager->new creates a 3 channel image, which has no alpha channel.

    To create a transparent image, create a 4 channel image:

    my $im = Imager->new(xsize => $width, ysize => $height, channels => 4);