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

Since your problem is almost certainly with the header, what's in $mime here?
print header(-type=>$mime);


Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...