[cgiapp] [RFC] Plugin: CGI::Application::Plugin::Image

Flavio Poletti flavio at polettix.it
Fri Jul 4 22:16:18 EDT 2008


Hi,

   I'm planning to put a plugin in CPAN with the name in the subject. The
goal is provide a method by means of which an image can be served
"quickly" (programmer-time-wise) via CGI::Application. An example is
given at the end of this message.

Actually, so far what I've thought is that it's only a matter of guessing
the right Content-Type and setting it. Moreover, I've added some
auto-detection to see if there's any GD/Image::Magick/Imager object, and
try to do the right thing (i.e. getting some data).

One thing that I'll add is the possibility to read the image from file, of
course.

Do you agree on the module name, or would you prefer something else?
CAP::Image seems a bit pretentious considering what the module does, I
wouldn't steal the name for something more promising in the future.

You can get the full module at
http://wiki.polettix.it/upload/CGI-Application-Plugin-Image-0.0.1.tar.gz

Cheers,

   Flavio.

---

package RandomBars;
use strict;
use warnings;
use base 'CGI::Application';
use CGI::Application::Plugin::Image;
use GD::Graph::bars;

sub setup {
   my $self = shift;
   $self->run_modes(image => \&image);
   $self->start_mode('image');
}

sub image {    # the run mode. Make up some image, then serve it
   my $self = shift;

   my $cgi    = $self->query();
   my $width  = $cgi->param('width') || 800;
   my $height = $cgi->param('height') || 600;
   my $n      = $cgi->param('n') || 10;
   my $r      = $cgi->param('r') || 50;

   my $g = GD::Graph::bars->new($width, $height);
   my @x = 1 .. $n;
   my @y = map { rand $r } @x;
   return $self->serve_image($g->plot([\@x, \@y]));
} ## end sub image



More information about the cgiapp mailing list