version 1.2, 2002/11/13 23:52:41
|
version 1.9, 2003/05/13 19:08:31
|
Line 34 use strict;
|
Line 34 use strict;
|
use Image::Magick; |
use Image::Magick; |
use Apache::Constants qw(:common); |
use Apache::Constants qw(:common); |
use Apache::loncommon(); |
use Apache::loncommon(); |
|
use GD; |
|
|
|
sub get_image { |
|
my ($imgsrc,$set_trans)=@_; |
|
my $image; |
|
if ($imgsrc !~ /\.(png|jpg|jpeg)$/i) { |
|
my $conv_image = Image::Magick->new; |
|
my $current_figure = $conv_image->Read('filename'=>$imgsrc); |
|
$conv_image->Set('magick'=>'png'); |
|
my @blobs=$conv_image->ImageToBlob(); |
|
undef $conv_image; |
|
$image = GD::Image->new($blobs[0]); |
|
} else { |
|
GD::Image->trueColor(1); |
|
$image = GD::Image->new($imgsrc); |
|
} |
|
if ($set_trans && defined($image)) { |
|
my $white=$image->colorExact(255,255,255); |
|
if ($white != -1) { $image->transparent($white); } |
|
} |
|
return $image; |
|
} |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
Line 41 sub handler {
|
Line 63 sub handler {
|
my (undef,$token) = split(/=/,$ENV{'QUERY_STRING'}); |
my (undef,$token) = split(/=/,$ENV{'QUERY_STRING'}); |
&Apache::loncommon::get_unprocessed_cgi( |
&Apache::loncommon::get_unprocessed_cgi( |
&Apache::lonnet::unescape($ENV{'imagerequest.'.$token})); |
&Apache::lonnet::unescape($ENV{'imagerequest.'.$token})); |
&Apache::lonnet::delenv('imagerequest\.'.$token); |
my $image=&get_image($ENV{"form.BGIMG"},0); |
my $image = Image::Magick->new; |
if (! defined($image)) { |
my $current_figure = $image->Read('filename'=>$ENV{"form.BGIMG"}); |
&Apache::lonnet::logthis('Unable to create image object for '. |
|
$ENV{"form.BGIMG"}); |
|
return OK; |
|
} |
#binmode(STDOUT); |
#binmode(STDOUT); |
|
my $black; |
|
if (!($black=$image->colorResolve(0,0,0))) { |
|
$black = $image->colorClosestHWB(0,0,0); |
|
} |
for(my $i=0;$i<$ENV{"form.ICOUNT"};$i++) { |
for(my $i=0;$i<$ENV{"form.ICOUNT"};$i++) { |
my $subimage = Image::Magick->new; |
my $subimage=&get_image($ENV{"form.IMG$i"},1); |
$subimage->Read('filename' => $ENV{"form.IMG$i"}); |
if (!defined($subimage)) { |
$image->Composite('x' => $ENV{"form.X$i"},'y' => $ENV{"form.Y$i"}, |
&Apache::lonnet::logthis('Unable to create image object for '. |
'compose'=> 'Over', 'image' => $subimage, |
$ENV{"form.BGIMG"}); |
'gravity' => 'NorthWest'); |
next; |
undef($subimage); |
} |
|
$image->copy($subimage,$ENV{"form.IX$i"},$ENV{"form.IY$i"}, |
|
0,0,$subimage->getBounds()); |
} |
} |
|
my $height=GD::Font->Giant->height; |
for(my $i=0;$i<$ENV{"form.COUNT"};$i++) { |
for(my $i=0;$i<$ENV{"form.COUNT"};$i++) { |
$image->Annotate('text' => $ENV{"form.LB$i"},'x' => $ENV{"form.X$i"}, |
$image->string(gdGiantFont,$ENV{"form.X$i"},$ENV{"form.Y$i"}-$height, |
'y' => $ENV{"form.Y$i"}, 'font' => 'Times-Bold', |
$ENV{"form.LB$i"},$black); |
'pointsize' => 18, 'antialias' => 'true', |
} |
'gravity' => 'NorthWest'); |
$r->print($image->png); |
} |
|
$image->Set('magick'=>'png'); |
|
my @blobs=$image->ImageToBlob(); |
|
$r->print($blobs[0]); |
|
return OK; |
return OK; |
} |
} |
|
|