Diff for /loncom/homework/drawimage.pm between versions 1.11 and 1.12

version 1.11, 2024/04/05 02:31:23 version 1.12, 2024/04/05 04:05:08
Line 29 Line 29
 package Apache::drawimage;  package Apache::drawimage;
 use strict;  use strict;
 use Apache::loncommon;  use Apache::loncommon;
   use Apache::lonnet;
   use Apache::lonxml;
 use lib '/home/httpd/lib/perl/';  use lib '/home/httpd/lib/perl/';
   use Time::HiRes qw(gettimeofday);
 use LONCAPA;  use LONCAPA;
     
   
Line 54  sub start_drawimage { Line 57  sub start_drawimage {
 sub end_drawimage {  sub end_drawimage {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;      my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
     my $result;      my $result;
       # need to call rand everytime start_script would evaluate, as the
       # safe space rand number generator and the global rand generator
       # are not separate
       my $randnumber;
       if ($target eq 'web' || $target eq 'tex' || $target eq 'grade' ||
           $target eq 'answer') {
           $randnumber=int(rand(1000));
       }
     if ($target eq 'web' || $target eq 'tex') {      if ($target eq 'web' || $target eq 'tex') {
  my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);   my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
  my $height =&Apache::lonxml::get_param('height',$parstack,$safeeval);   my $height =&Apache::lonxml::get_param('height',$parstack,$safeeval);
  my $bgcolor =&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);   my $bgcolor =&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
  if (!$width) { $width=300; }   if (!$width) { $width=300; }
  if (!$height) { $height=300; }   if (!$height) { $height=300; }
  $result.="<img width='$width' height='$height'          $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));
           if ($target eq 'tex') {
               my $texwidth=&Apache::lonxml::get_param('texwidth',$parstack,$safeeval,undef,1);
               if (!$texwidth) { $texwidth='90'; }
               $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height,$texwidth));
               my $tmpdir = LONCAPA::tempdir(); # Where temporary files live:
               ## Determine filename
               my ($seconds, $microseconds) = gettimeofday;
               my $filename = $env{'user.name'}.'_'.$env{'user.domain'}.
                              '_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber.'_drawimage.eps';
               $args{"cgi.$cgi_id.EPSFILE"} = $env{'user.name'}.'_'.$env{'user.domain'}.
                                              '_'.$seconds.'_'.$microseconds.'_'.$$.$randnumber.
                                              '_drawimage.eps';
               $result = "%DYNAMICIMAGE:$width:$height:$texwidth\n";
               $result .= '\graphicspath{{'.$tmpdir.'}}'."\n";
               $result .= '\includegraphics[width='.$texwidth.' mm]{'.$filename.'}';
               &Apache::lonxml::register_ssi('/adm/randomlabel.png?token='.$cgi_id);
           } else {
       $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));
       $result.="<img width='$width' height='$height'
                            src='/adm/randomlabel.png?token=$cgi_id' />\n";                             src='/adm/randomlabel.png?token=$cgi_id' />\n";
  $args{"cgi.$cgi_id.SIZE"}=join(':',($width,$height));          }
  $args{"cgi.$cgi_id.BGCOLOR"}=join(':',($bgcolor));  
  &Apache::lonnet::appenv(\%args);   &Apache::lonnet::appenv(\%args);
  if (@cgi_ids) {   if (@cgi_ids) {
     $cgi_id=pop(@cgi_ids);      $cgi_id=pop(@cgi_ids);

Removed from v.1.11  
changed lines
  Added in v.1.12


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>