CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Multiple GD Objects

 



Sam Kennedy
Novice

Aug 28, 2012, 6:39 AM

Post #1 of 4 (1445 views)
Multiple GD Objects Can't Post

I'm working on some code which handles 10 images. To create an image object with GD you use:


Code
$im1 = new GD::Image($width,$height,1);


However, since I'm using 10 images, I don't want to write:

Code
$im1 = ... 
$im2 = ...
$im3 = ...


So I used a for loop and:

Code
${"im".$i} = new GD::Image($width,$height,1);


Where $i would be the image number, however this doesn't work.

What would be a better way of handling multiple GD objects?

Thank You :)
-Sam


FishMonger
Veteran / Moderator

Aug 28, 2012, 6:44 AM

Post #2 of 4 (1443 views)
Re: [Sam Kennedy] Multiple GD Objects [In reply to] Can't Post

Use an array.


Code
my @image; 
for (1..10) {
push @image, GD::Image->new($width,$height,1);
}



FishMonger
Veteran / Moderator

Aug 28, 2012, 6:57 AM

Post #3 of 4 (1440 views)
Re: [Sam Kennedy] Multiple GD Objects [In reply to] Can't Post

I should also point out that you could use a hash, if you wanted to refer to them by name.

Code
my %image; 

foreach my $name ( qw(foo bar bazz) ) {
$image{$name} = GD::Image->($width,$height,1);
}



Sam Kennedy
Novice

Aug 28, 2012, 11:28 AM

Post #4 of 4 (1435 views)
Re: [Sam Kennedy] Multiple GD Objects [In reply to] Can't Post

Thank you very much, it's sorted now :)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives