--- loncom/xml/londefdef.pm 2004/04/15 17:37:04 1.209 +++ loncom/xml/londefdef.pm 2004/04/15 19:08:31 1.210 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.209 2004/04/15 17:37:04 albertel Exp $ +# $Id: londefdef.pm,v 1.210 2004/04/15 19:08:31 albertel Exp $ # # # Copyright Michigan State University Board of Trustees @@ -2333,27 +2333,46 @@ sub start_img { if ($height) { $currentstring.=' height="'.$height.'" '; } $currentstring .= ' />'; } elsif ($target eq 'modified') { - my $constructtag=&Apache::edit::get_new_args($token,$parstack, - $safeeval,'src','alt', - 'TeXwidth','TeXheight', - 'width','height'); - $src=$token->[2]{'src'}; - if (!$token->[2]{'width'} && !$token->[2]{'height'}) { - $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - &image_replication($src); - if (-e $src) { - my $image = Image::Magick->new; - $image->Read($src); - my ($width, $height) = ($image->Get('width'), - $image->Get('height')); - if ($width && $height) { - $token->[2]{'width'} =$width; - $token->[2]{'height'}=$height; - $constructtag=1; + my ($osrc,$owidth,$oheight)= + ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); + my $ctag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'src','alt', + 'TeXwidth','TeXheight', + 'width','height'); + my ($nsrc,$nwidth,$nheight)= + ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'}); + my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc); + &image_replication($loc); + my ($iwidth,$iheight); + &Apache::lonnet::logthis("loc is $loc"); + if (-e $loc) { + my $image = Image::Magick->new; + $image->Read($loc); + ($iwidth, $iheight) = ($image->Get('width'), + $image->Get('height')); + } + if ($osrc ne $nsrc || (!$nwidth && !$nheight)) { + # changed image or no size specified, + # if they didn't explicitly change the + # width or height use the ones from the image + if ($iwidth && $iheight) { + if ($owidth == $nwidth || (!$nwidth && !$nheight)) { + $token->[2]{'width'} = $iwidth;$ctag=1; + } + if ($oheight == $nheight || (!$nwidth && !$nheight)) { + $token->[2]{'height'}=$iheight;$ctag=1; } } } - if ($constructtag) {$currentstring=&Apache::edit::rebuild_tag($token);} + my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'}); + # if we don't have a width or height + if ($iwidth && $cwidth && !$cheight) { + $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1; + } + if ($iheight && $cheight && !$cwidth) { + $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1; + } + if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);} } return $currentstring; }