version 1.15, 2004/02/11 21:51:15
|
version 1.16, 2004/02/23 22:52:30
|
Line 88 sub get_image {
|
Line 88 sub get_image {
|
return $image; |
return $image; |
} |
} |
|
|
|
sub get_color_from_hexstring { |
|
my ($image,$color)=@_; |
|
if (!$color) { $color='000000'; } |
|
my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color); |
|
$red=hex($red);$green=hex($green);$blue=hex($blue); |
|
my $imcolor; |
|
if (!($imcolor = $image->colorResolve($red,$green,$blue))) { |
|
$imcolor = $image->colorClosestHWB($red,$green,$blue); |
|
} |
|
return $imcolor; |
|
} |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
$r->content_type('image/png'); |
$r->content_type('image/png'); |
Line 99 sub handler {
|
Line 111 sub handler {
|
&Apache::lonnet::logthis('Unable to create image object for -'.$id.'-'. |
&Apache::lonnet::logthis('Unable to create image object for -'.$id.'-'. |
$ENV{"cgi.$id.BGIMG"}); |
$ENV{"cgi.$id.BGIMG"}); |
return OK; |
return OK; |
|
} elsif (defined($ENV{"cgi.$id.SIZE"})) { |
|
my ($width,$height)=split(':',$ENV{"cgi.$id.SIZE"}); |
|
$image = new GD::Image($width,$height,1); |
|
my ($bgcolor)=split(':',$ENV{"cgi.$id.BGCOLOR"}); |
|
if ($bgcolor ne 'transparent') { |
|
$bgcolor=&get_color_from_hexstring($image,$bgcolor); |
|
# $image->rectangle(0,0,$width,$height,$bgcolor); |
|
$image->fill(0,0,$bgcolor); |
|
} else { |
|
$bgcolor=&get_color_from_hexstring($image,'FFFFFF'); |
|
$image->fill(0,0,$bgcolor); |
|
$image->transparent($bgcolor); |
|
} |
|
} else { |
|
&Apache::lonnet::logthis('Unable to create image object, no info'); |
|
return OK; |
} |
} |
#binmode(STDOUT); |
#binmode(STDOUT); |
my $black; |
my @objtypes=split(':',$ENV{"cgi.$id.OBJTYPE"}); |
if (!($black=$image->colorResolve(0,0,0))) { |
foreach(my $i=0;$i<$ENV{"cgi.$id.OBJCOUNT"};$i++) { |
$black = $image->colorClosestHWB(0,0,0); |
my $type=shift(@objtypes); |
} |
&Apache::lonnet::logthis("type is $type"); |
for(my $i=0;$i<$ENV{"cgi.$id.ICOUNT"};$i++) { |
if ($type eq 'LINE') { |
my $subimage=&get_image(&Apache::lonnet::unescape($ENV{"cgi.$id.IMG$i"}),1); |
my ($x1,$y1,$x2,$y2,$color,$thickness)= |
if (!defined($subimage)) { |
split(':',$ENV{"cgi.$id.OBJ$i"}); |
&Apache::lonnet::logthis('Unable to create image object for '. |
my $imcolor=&get_color_from_hexstring($image,$color); |
$ENV{"cgi.$id.BGIMG"}); |
if (!defined($thickness)) { $thickness=1; } |
next; |
$image->setThickness($thickness); |
} |
$image->setAntiAliased($imcolor); |
$image->copy($subimage,$ENV{"cgi.$id.IX$i"},$ENV{"cgi.$id.IY$i"}, |
$image->line($x1,$y1,$x2,$y2,gdAntiAliased); |
0,0,$subimage->getBounds()); |
} elsif ($type eq 'RECTANGLE') { |
} |
my ($x1,$y1,$x2,$y2,$color,$thickness,$filled)= |
my $height=GD::Font->Giant->height; |
split(':',$ENV{"cgi.$id.OBJ$i"}); |
for(my $i=0;$i<$ENV{"cgi.$id.COUNT"};$i++) { |
if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; } |
$image->string(GD::gdGiantFont,$ENV{"cgi.$id.X$i"}, |
if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; } |
$ENV{"cgi.$id.Y$i"}-$height, |
my $imcolor=&get_color_from_hexstring($image,$color); |
&Apache::lonnet::unescape($ENV{"cgi.$id.LB$i"}),$black); |
if (!defined($thickness)) { $thickness=1; } |
} |
$image->setThickness($thickness); |
for(my $i=0;$i<$ENV{"cgi.$id.LINECOUNT"};$i++) { |
# $image->setAntiAliased($imcolor); |
my ($x1,$y1,$x2,$y2,$color,$width)=split(':',$ENV{"cgi.$id.LINE$i"}); |
if ($filled) { |
my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color); |
$image->filledRectangle($x1,$y1,$x2,$y2,$imcolor); |
$red=hex($red);$green=hex($green);$blue=hex($blue); |
} else { |
my $imcolor; |
$image->rectangle($x1,$y1,$x2,$y2,$imcolor); |
if (!($imcolor = $image->colorResolve($red,$green,$blue))) { |
} |
$imcolor = $image->colorClosestHWB($red,$green,$blue); |
} elsif ($type eq 'POLYGON') { |
} |
my ($color,$width,$open)=split(':',$ENV{"cgi.$id.OBJ$i"}); |
$image->setThickness($width); |
my $imcolor=&get_color_from_hexstring($image,$color); |
$image->line($x1,$y1,$x2,$y2,$imcolor); |
my $polygon = (($open) ? (new GD::Polyline) : (new GD::Polygon)); |
} |
foreach my $coord (split('-',$ENV{"cgi.$id.OBJEXTRA$i"})) { |
for(my $i=0;$i<$ENV{"cgi.$id.BOXCOUNT"};$i++) { |
my ($x,$y)=($coord=~m/\(([0-9]+),([0-9]+)\)/); |
my ($x1,$y1,$x2,$y2,$color,$width)=split(':',$ENV{"cgi.$id.BOX$i"}); |
$polygon->addPt($x,$y); |
if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; } |
} |
if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; } |
$image->setThickness($width); |
my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color); |
if ($open) { |
$red=hex($red);$green=hex($green);$blue=hex($blue); |
$image->polydraw($polygon,$imcolor); |
my $imcolor; |
} else { |
if (!($imcolor = $image->colorResolve($red,$green,$blue))) { |
$image->polygon($polygon,$imcolor); |
$imcolor = $image->colorClosestHWB($red,$green,$blue); |
} |
} |
} elsif ($type eq 'ARC') { |
$image->setThickness($width); |
my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)= |
$image->rectangle($x1,$y1,$x2,$y2,$imcolor); |
split(':',$ENV{"cgi.$id.OBJ$i"}); |
} |
if (!$color) { $color='000000'; } |
for(my $i=0;$i<$ENV{"cgi.$id.POLYCOUNT"};$i++) { |
my $imcolor=&get_color_from_hexstring($image,$color); |
my ($color,$width,$open)=split(':',$ENV{"cgi.$id.POLYOPT$i"}); |
if (!defined($thickness)) { $thickness=1; } |
my (undef,$red,undef,$green,undef,$blue)=split(/(..)/,$color); |
$image->setThickness($thickness); |
$red=hex($red);$green=hex($green);$blue=hex($blue); |
# $image->setAntiAliased($imcolor); |
my $imcolor; |
if ($filled) { |
if (!($imcolor = $image->colorResolve($red,$green,$blue))) { |
$image->filledArc($x,$y,$width,$height,$start,$end, |
$imcolor = $image->colorClosestHWB($red,$green,$blue); |
$imcolor); |
} |
} else { |
my $polygon; |
$image->arc($x,$y,$width,$height,$start,$end,$imcolor); |
if ($open) { |
} |
$polygon = new GD::Polyline; |
} elsif ($type eq 'FILL') { |
} else { |
my ($x,$y,$color)=split(':',$ENV{"cgi.$id.OBJ$i"}); |
$polygon = new GD::Polygon; |
if (!$color) { $color='000000'; } |
} |
my $imcolor=&get_color_from_hexstring($image,$color); |
foreach my $coord (split('-',$ENV{"cgi.$id.POLY$i"})) { |
$image->fill($x,$y,$imcolor); |
my ($x,$y)=($coord=~m/\(([0-9]+),([0-9]+)\)/); |
} elsif ($type eq 'IMAGE') { |
$polygon->addPt($x,$y); |
my ($x,$y,$file,$transparent)=split(':',$ENV{"cgi.$id.OBJ$i"}); |
} |
$file=&Apache::lonnet::unescape($file); |
$image->setThickness($width); |
if (!defined($transparent)) { $transparent=1; } |
if ($open) { |
my $subimage=&get_image($file,$transparent); |
$image->polydraw($polygon,$imcolor); |
if (!defined($subimage)) { |
} else { |
&Apache::lonnet::logthis('Unable to create image object for '. |
$image->polygon($polygon,$imcolor); |
$file); |
|
next; |
|
} |
|
$image->copy($subimage,$x,$y,0,0,$subimage->getBounds()); |
|
} elsif ($type eq 'LABEL') { |
|
my ($x,$y,$text,$font,$color)=split(':',$ENV{"cgi.$id.OBJ$i"}); |
|
$text=&Apache::lonnet::unescape($text); |
|
my $imcolor=&get_color_from_hexstring($image,$color); |
|
my $height=GD::Font->Giant->height; |
|
for(my $i=0;$i<$ENV{"cgi.$id.COUNT"};$i++) { |
|
$image->string(GD::gdGiantFont,$x,$y-$height,$text,$black); |
|
} |
} |
} |
} |
} |
$image->setThickness(1); |
$image->setThickness(1); |