Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Imager transparent background instead of black

by Anonymous Monk
on Nov 10, 2010 at 19:03 UTC ( [id://870652]=perlquestion: print w/replies, xml ) Need Help??

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 (Pilgrim) 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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://870652]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found