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

Mike Friedman friedo at friedo.com
Tue Jul 8 10:08:02 EDT 2008


Hi Flavio,

Looks like a pretty useful plugin. I especially like that it tries to
guess the correct content type. I think I will try to use it in one of
my apps that has to serve a bunch of dynamic images; it should allow
me to eliminate some tedious, repetitive code. I'll let you know how
it goes.

For now, go ahead and put it up on CPAN! Also post an entry on the
wiki here: http://cgi-app.org/index.cgi?Plugins


Mike

On Fri, Jul 4, 2008 at 10:16 PM, Flavio Poletti <flavio at polettix.it> wrote:
> 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
>
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
>
>


More information about the cgiapp mailing list