--- loncom/homework/randomlabel.pm 2005/06/28 14:58:23 1.78 +++ loncom/homework/randomlabel.pm 2005/07/14 04:08:55 1.79 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # random labelling tool # -# $Id: randomlabel.pm,v 1.78 2005/06/28 14:58:23 albertel Exp $ +# $Id: randomlabel.pm,v 1.79 2005/07/14 04:08:55 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -369,6 +369,21 @@ sub get_label_width { } + +sub get_label_height { + my $label = shift; + &Apache::lonxml::debug("image label = $label"); + if (-e $label) { + &Apache::lonxml::debug("$label exists"); + } else { + &Apache::lonxml::debug("$label does not exist"); + } + my $magick = Image::Magick->new; + $magick->Read($label); + my $pixel_height = $magick->Get('height'); + return $pixel_height * $scale_factor; +} + sub add_vars { my ($name,$order,$label,$labelorder,$value,$image,$safeeval) = @_; if (!defined($name) || $name eq '') { return; } @@ -446,6 +461,11 @@ sub end_labelgroup { #y latex coordinate # my $ratio=($wwidth > 0 ? $wheight/$wwidth : 1 ); my $tcY=$height_param-$y*($height_param/$wheight); + if ( $type eq 'image') { + my $label_height = &get_label_height($label); + $tcY=$tcY-$label_height; + } + &Apache::lonxml::debug("hparam = $height_param wheight = $wheight texy = $tcY"); $tcX=sprintf('%.2f',$tcX); $tcY=sprintf('%.2f',$tcY); @@ -456,7 +476,7 @@ sub end_labelgroup { } elsif ( $type eq 'image') { my ($path,$file) = &Apache::londefdef::get_eps_image($label); my $image_name = $path.$file; - my $label_width = get_label_width($label); + my $label_width = &get_label_width($label); $result .= '\includegraphics[width='.$label_width.'mm]{' .$image_name."}}\n";