Annotation of loncom/homework/randomlylabel.pm, revision 1.2
1.1 albertel 1: #!/usr/bin/perl
2: # The LearningOnline Network with CAPA
3: # randomlabel.png: composite together text and images into 1 image
4: #
1.2 ! albertel 5: # $Id: randomlylabel.pm,v 1.1 2002/11/08 14:37:42 albertel Exp $
1.1 albertel 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
29: ###
30:
31: package Apache::randomlylabel;
32:
33: use strict;
34: use Image::Magick;
35: use Apache::Constants qw(:common);
36: use Apache::loncommon();
37:
38: sub handler {
39: my $r = shift;
40: $r->content_type('image/png');
41: my (undef,$token) = split(/=/,$ENV{'QUERY_STRING'});
42: &Apache::loncommon::get_unprocessed_cgi(
43: &Apache::lonnet::unescape($ENV{'imagerequest.'.$token}));
44: &Apache::lonnet::delenv('imagerequest\.'.$token);
45: my $image = Image::Magick->new;
46: my $current_figure = $image->Read('filename'=>$ENV{"form.BGIMG"});
47: #binmode(STDOUT);
48: for(my $i=0;$i<$ENV{"form.ICOUNT"};$i++) {
49: my $subimage = Image::Magick->new;
50: $subimage->Read('filename' => $ENV{"form.IMG$i"});
51: $image->Composite('x' => $ENV{"form.X$i"},'y' => $ENV{"form.Y$i"},
1.2 ! albertel 52: 'compose'=> 'Over', 'image' => $subimage,
! 53: 'gravity' => 'NorthWest');
1.1 albertel 54: undef($subimage);
55: }
56: for(my $i=0;$i<$ENV{"form.COUNT"};$i++) {
57: $image->Annotate('text' => $ENV{"form.LB$i"},'x' => $ENV{"form.X$i"},
58: 'y' => $ENV{"form.Y$i"}, 'font' => 'Times-Bold',
1.2 ! albertel 59: 'pointsize' => 18, 'antialias' => 'true',
! 60: 'gravity' => 'NorthWest');
1.1 albertel 61: }
62: $image->Set('magick'=>'png');
63: my @blobs=$image->ImageToBlob();
64: $r->print($blobs[0]);
65: return OK;
66: }
67:
68: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>