[LON-CAPA-cvs] cvs: loncom /xml londefdef.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Tue, 17 May 2005 23:27:28 -0000
foxr Tue May 17 19:27:28 2005 EDT
Modified files:
/loncom/xml londefdef.pm
Log:
Separate the final image size computation from the initial image size
determination in image_size -> resize_image. This allows resize_image
to be used in computing final sizing for images created on-the-fly e.g.
with gnuplot
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.270 loncom/xml/londefdef.pm:1.271
--- loncom/xml/londefdef.pm:1.270 Tue May 17 19:11:59 2005
+++ loncom/xml/londefdef.pm Tue May 17 19:27:25 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Tags Default Definition Module
#
-# $Id: londefdef.pm,v 1.270 2005/05/17 23:11:59 foxr Exp $
+# $Id: londefdef.pm,v 1.271 2005/05/17 23:27:25 foxr Exp $
#
#
# Copyright Michigan State University Board of Trustees
@@ -3766,21 +3766,33 @@
}
return '';
}
+#
+# Get correct sizing parameter for an image given
+# it's initial ht. and wid. This allows sizing of
+# images that are generated on-the-fly (e.g. gnuplot)
+# as well as serving as a utility for image_size.
+#
+# Parameter:
+# height_param
+# width_param - Initial picture dimensions.
+# scaling - A scale factor.
+# parstack,
+# safeeval,
+# depth,
+# cis - The usual xml stuff ???
+#
+# Returns:
+# height, width - new dimensions.
+#
+sub resize_image {
+ my ($height_param, $width_param, $scaling,
+ $parstack, $safeeval, $depth, $cis) = @_;
-sub image_size {
- my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
+ # First apply the scaling...
+
+ $height_param = $height_param * $scaling;
+ $width_param = $width_param * $scaling;
- #size of image from gif/jpg/jpeg/png
- my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
- if (-e $ressrc) {
- $src = $ressrc;
- }
- 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;
- &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
- undef($image);
#do we have any specified LaTeX size of the picture?
my $toget='TeXwidth';
if ($cis) {
@@ -3825,6 +3837,29 @@
$height_param=$width_param/$old_width_param*$height_param;
}
}
+
+ return ($height_param, $width_param);
+}
+
+sub image_size {
+ my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
+
+ #size of image from gif/jpg/jpeg/png
+ my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
+ if (-e $ressrc) {
+ $src = $ressrc;
+ }
+ my $image = Image::Magick->new;
+ my $current_figure = $image->Read($src);
+ my $width_param = $image->Get('width');
+ my $height_param = $image->Get('height');
+ &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
+ undef($image);
+
+ ($height_param, $width_param) = &resize_image($height_param, $width_param,
+ $scaling, $parstack, $safeeval,
+ $depth, $cis);
+
return ($height_param, $width_param);
}