Diff for /loncom/homework/randomlylabel.pm between versions 1.4 and 1.10

version 1.4, 2002/12/16 14:41:15 version 1.10, 2003/11/10 23:29:27
Line 39  use GD; Line 39  use GD;
 sub get_image {  sub get_image {
     my ($imgsrc,$set_trans)=@_;      my ($imgsrc,$set_trans)=@_;
     my $image;      my $image;
     if ($imgsrc !~ /\.(png|jpg|jpeg)$/) {      if ($imgsrc !~ /\.(png|jpg|jpeg)$/i) {
  my $conv_image = Image::Magick->new;   my $conv_image = Image::Magick->new;
  my $current_figure = $conv_image->Read('filename'=>$imgsrc);   my $current_figure = $conv_image->Read('filename'=>$imgsrc);
  $conv_image->Set('magick'=>'png');   $conv_image->Set('magick'=>'png');
Line 47  sub get_image { Line 47  sub get_image {
  undef $conv_image;   undef $conv_image;
  $image = GD::Image->new($blobs[0]);   $image = GD::Image->new($blobs[0]);
     } else {      } else {
    GD::Image->trueColor(1);
  $image = GD::Image->new($imgsrc);   $image = GD::Image->new($imgsrc);
     }      }
     if ($set_trans) {      if ($set_trans && defined($image)) {
  my $white=$image->colorExact(255,255,255);   my $white=$image->colorExact(255,255,255);
  if ($white != -1) { $image->transparent($white); }   if ($white != -1) { $image->transparent($white); }
     }      }
Line 62  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=&get_image($ENV{"form.BGIMG"},0);
     if (! defined($image)) {      if (! defined($image)) {
         &Apache::lonnet::logthis('Unable to create image object for '.$ENV{"form.BGIMG"});          &Apache::lonnet::logthis('Unable to create image object for '.
    $ENV{"form.BGIMG"});
         return OK;          return OK;
     }      }
     #binmode(STDOUT);      #binmode(STDOUT);
     my $black = $image->colorAllocate(0,0,0);      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=&get_image($ENV{"form.IMG$i"},1);   my $subimage=&get_image($ENV{"form.IMG$i"},1);
  $image->copy($subimage,$ENV{"form.X$i"},$ENV{"form.Y$i"},   if (!defined($subimage)) {
               &Apache::lonnet::logthis('Unable to create image object for '.
                                    $ENV{"form.BGIMG"});
               next;
           }
    $image->copy($subimage,$ENV{"form.IX$i"},$ENV{"form.IY$i"},
      0,0,$subimage->getBounds());       0,0,$subimage->getBounds());
     }      }
     my $height=GD::Font->Giant->height;      my $height=GD::Font->Giant->height;
Line 80  sub handler { Line 89  sub handler {
  $image->string(gdGiantFont,$ENV{"form.X$i"},$ENV{"form.Y$i"}-$height,   $image->string(gdGiantFont,$ENV{"form.X$i"},$ENV{"form.Y$i"}-$height,
        $ENV{"form.LB$i"},$black);         $ENV{"form.LB$i"},$black);
     }      }
       for(my $i=0;$i<$ENV{"form.LINECOUNT"};$i++) {
    my $x1=$ENV{"form.LINEX1$i"};
    my $y1=$ENV{"form.LINEY1$i"};
    my $x2=$ENV{"form.LINEX2$i"};
    my $y2=$ENV{"form.LINEY2$i"};
    my $width=$ENV{"form.LINEW$i"};
    my $color=$ENV{"form.LINEC$i"};
    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);
    }
    $image->setThickness($width);
           $image->line($x1,$y1,$x2,$y2,$imcolor);
       }
       $image->setThickness(1);
     $r->print($image->png);      $r->print($image->png);
     return OK;      return OK;
 }  }

Removed from v.1.4  
changed lines
  Added in v.1.10


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