Annotation of loncom/cgi/randomlabel.png, revision 1.1
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: #
! 5: # $Id$
! 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: use strict;
! 32: use Image::Magick;
! 33:
! 34: sub unescape {
! 35: my $str=shift;
! 36: $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
! 37: return $str;
! 38: }
! 39:
! 40: sub add_to_env {
! 41: my ($name,$value)=@_;
! 42: if (defined($ENV{$name})) {
! 43: if (ref($ENV{$name})) {
! 44: #already have multiple values
! 45: push(@{ $ENV{$name} },$value);
! 46: } else {
! 47: #first time seeing multiple values, convert hash entry to an arrayref
! 48: my $first=$ENV{$name};
! 49: undef($ENV{$name});
! 50: push(@{ $ENV{$name} },$first,$value);
! 51: }
! 52: } else {
! 53: $ENV{$name}=$value;
! 54: }
! 55: }
! 56:
! 57: sub get_unprocessed_cgi {
! 58: my ($query,$possible_names)= @_;
! 59: # $Apache::lonxml::debug=1;
! 60: foreach (split(/&/,$query)) {
! 61: my ($name, $value) = split(/=/,$_);
! 62: $name = &unescape($name);
! 63: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
! 64: $value =~ tr/+/ /;
! 65: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
! 66: unless (defined($ENV{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
! 67: }
! 68: }
! 69: }
! 70:
! 71: sub main {
! 72: print <<END;
! 73: Content-type: image/png
! 74:
! 75: END
! 76: &get_unprocessed_cgi($ENV{'QUERY_STRING'});
! 77: my $image = Image::Magick->new;
! 78: # foreach my $envkey (sort(keys(%ENV))) {
! 79: # print("$envkey => $ENV{$envkey}\n");
! 80: # }
! 81: my $current_figure = $image->Read('filename'=>$ENV{"form.BGIMG"});
! 82: binmode(STDOUT);
! 83: # for(my $i=0;$i<$ENV{"form.ICOUNT"};$i++) {
! 84: #
! 85: # }
! 86: for(my $i=0;$i<$ENV{"form.COUNT"};$i++) {
! 87: $image->Annotate('text' => $ENV{"form.LB$i"},'x' => $ENV{"form.X$i"},
! 88: 'y' => $ENV{"form.Y$i"}, 'font' => 'Times-Bold',
! 89: 'pointsize' => 18, 'antialias' => 'true');
! 90: }
! 91: $image->Write('png:-');
! 92: my @fonts=$image->QueryFont();
! 93: # print(join(':',@fonts));
! 94:
! 95: }
! 96:
! 97: &main();
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>