--- loncom/xml/londefdef.pm 2004/01/28 20:41:15 1.196 +++ loncom/xml/londefdef.pm 2004/01/30 17:31:06 1.197 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.196 2004/01/28 20:41:15 albertel Exp $ +# $Id: londefdef.pm,v 1.197 2004/01/30 17:31:06 sakharuk Exp $ # # # Copyright Michigan State University Board of Trustees @@ -2085,8 +2085,6 @@ sub start_img { } $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=$src; my $currentstring = ''; - my $width_param = ''; - my $height_param = ''; my $scaling = .3; if ($target eq 'web') { if ($ENV{'browser.imagesuppress'} ne 'on') { @@ -2100,42 +2098,13 @@ sub start_img { } $currentstring.='[IMAGE: '.$alttag.']'; } - $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - &image_replication($src); } elsif ($target eq 'tex') { $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src); - &image_replication($src); #if original gif/jpg/png file exist do following: if (-e $src) { - #defines the default size of image - my $image = Image::Magick->new; - my $current_figure = $image->Read($src); - $width_param = $image->Get('width') * $scaling;; - $height_param = $image->Get('height') * $scaling;; - undef $image; - #do we have any specified size of the picture? - my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); - my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); - my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval, - undef,1); - if ($TeXwidth ne '') { - if ($TeXwidth=~/(\d+)\s*\%/) { - $width_param = $1*$ENV{'form.textwidth'}/100; - } else { - $width_param = $TeXwidth; - } - } elsif ($TeXheight ne '') { - $width_param = $TeXheight/$height_param*$width_param; - } elsif ($width ne '') { - $width_param = $width*$scaling; - } - if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} - my $file; - my $path; - if ($src =~ m!(.*)/([^/]*)$!) { - $file = $2; - $path = $1.'/'; - } + #what is the image size? + my $width_param=&image_size($src,$scaling,$parstack,$safeeval); + my ($file,$path)=&file_path($src); my $newsrc = $src; $newsrc =~ s/\.(gif|jpg|png)$/.eps/i; $file=~s/\.(gif|jpg|png)$/.eps/i; @@ -3340,6 +3309,35 @@ sub image_replication { return ''; } +sub image_size { + my ($src,$scaling,$parstack,$safeeval)=@_; + #size of image from gif/jpg/jpeg/png + my $image = Image::Magick->new; + my $current_figure = $image->Read($src); + my $width_param = $image->Get('width') * $scaling;; + my $height_param = $image->Get('height') * $scaling;; + undef $image; + #do we have any specified LaTeX size of the picture? + my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); + my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); + #do we have any specified web size of the picture? + my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval, + undef,1); + if ($TeXwidth ne '') { + if ($TeXwidth=~/(\d+)\s*\%/) { + $width_param = $1*$ENV{'form.textwidth'}/100; + } else { + $width_param = $TeXwidth; + } + } elsif ($TeXheight ne '') { + $width_param = $TeXheight/$height_param*$width_param; + } elsif ($width ne '') { + $width_param = $width*$scaling; + } + if ($width_param > $ENV{'form.textwidth'}) {$width_param =0.95*$ENV{'form.textwidth'}} + return $width_param; +} + sub eps_generation { my ($src,$file,$width_param) = @_; my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat"; @@ -3354,6 +3352,16 @@ sub eps_generation { return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} '; } +sub file_path { + my $src=shift; + my ($file,$path); + if ($src =~ m!(.*)/([^/]*)$!) { + $file = $2; + $path = $1.'/'; + } + return $file,$path; +} + sub recalc { my $argument = shift; if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}