in reply to Using GD in a CGI script to randomly select images fails...

Did you try use CGI::Carp qw(fatalsToBrowser);?

You don't guard ->new against potential failures (e.g. wrong pathes).

And try to print the header as early as possible (it's always 'Content-Type: image/png', it seems) to facilitate debugging.