--- loncom/homework/randomlylabel.pm 2024/04/05 02:43:25 1.35 +++ loncom/homework/randomlylabel.pm 2024/04/05 04:05:08 1.36 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # randomlabel.png: composite together text and images into 1 image # -# $Id: randomlylabel.pm,v 1.35 2024/04/05 02:43:25 raeburn Exp $ +# $Id: randomlylabel.pm,v 1.36 2024/04/05 04:05:08 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -302,8 +302,6 @@ sub add_click { sub handler { my $r = shift; - $r->content_type('image/png'); - $r->send_http_header; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); @@ -313,6 +311,22 @@ sub handler { } else { $prefix="cgi.$env{'form.token'}."; } + my $epsfile; + if (defined($env{$prefix."EPSFILE"})) { + my $user = $env{'user.name'}.'_'.$env{'user.domain'}; + if ($env{$prefix."EPSFILE"} =~ /^\Q$user\E_\d+_\d+_\d+_drawimage\.eps$/) { + $epsfile = $Apache::lonnet::perlvar{'lonPrtDir'}.'/'.$env{$prefix."EPSFILE"}; + } else { + &Apache::lonnet::logthis('Unable to create eps file for image object for -'. + $env{'form.token'}.'- for '.$user.' as EPSFILE has '. + 'unexpected value'); + return OK; + } + } + unless ($epsfile) { + $r->content_type('image/png'); + $r->send_http_header; + } my $image; if (defined($env{$prefix."BGIMG"})) { @@ -472,7 +486,16 @@ sub handler { } if (exists($env{'form.clickdata'})) { &add_click($image); } $image->setThickness(1); - $r->print($image->png); + if ($epsfile) { + if (open(my $pipe, "| convert png:- $epsfile")) { + print $pipe $image->png; + close($pipe); + } else { + &Apache::lonnet::logthis("randomlylabel unable to open pipe to convert png to eps"); + } + } else { + $r->print($image->png); + } return OK; }