antoine 2003/08/22 02:20:56 Modified: . WHATSNEW src/main/org/apache/tools/ant/types/optional/image Scale.java src/etc/testcases/taskdefs/optional/image image.xml docs/manual/OptionalTasks image.html Log: Quoting Rob Oxspring : I was using the image task to create thumbnails and couldn't figure out how to keep proportions of an image but keep it within a fixed size. My solution was to change the keepproportions attribute to be a little cleverer. The keepproportions attribute is no more and has been replaced by the proportions attribute, which has been added with the following features: proportions="ignore" - treat the dimensions independently (==keepproportions="false" and is default) proportions="width" - keep proportions based on the width (==keepproportions="true") proportions="height" - keep proportions based on the height proportions="fit" - keep proportions and fit in the supplied dimensions proportions="cover" - keep proportions and cover the supplied dimensions Submitted by: Rob Oxspring (roxspring at imapmail dot org) Revision Changes Path 1.490 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.489 retrieving revision 1.490 diff -u -r1.489 -r1.490 --- WHATSNEW 21 Aug 2003 19:42:15 -0000 1.489 +++ WHATSNEW 22 Aug 2003 09:20:56 -0000 1.490 @@ -262,6 +262,9 @@ * Added <image> task (requires JAI). +* <image> task has now proportions attribute in the <scale/> nested element + instead of keepproportions (bringing in more functionality) + * New condition <isreference> * <ftp> now has a preservelastmodified attribute to preserve the 1.6 +34 -5 ant/src/main/org/apache/tools/ant/types/optional/image/Scale.java Index: Scale.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/optional/image/Scale.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Scale.java 22 Apr 2003 07:35:17 -0000 1.5 +++ Scale.java 22 Aug 2003 09:20:56 -0000 1.6 @@ -53,26 +53,42 @@ */ package org.apache.tools.ant.types.optional.image; +import org.apache.tools.ant.types.EnumeratedAttribute; + import javax.media.jai.JAI; import javax.media.jai.PlanarImage; +import javax.media.jai.InterpolationBilinear; +import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.awt.image.renderable.ParameterBlock; /** * * @author <a href="mailto:[EMAIL PROTECTED]">Kevin Z Grey</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Rob Oxspring</a> * @see org.apache.tools.ant.taskdefs.optional.image.Image */ public class Scale extends TransformOperation implements DrawOperation { + private String width_str = "100%"; private String height_str = "100%"; private boolean x_percent = true; private boolean y_percent = true; - private boolean keep_proportions = false; + private String proportions = "ignore"; + + public static class ProportionsAttribute extends EnumeratedAttribute { + public String[] getValues() { + return new String[] {"ignore", "width", "height", "cover", "fit"}; + } + } - public void setKeepproportions(boolean props) { - keep_proportions = props; + /** + * Sets the behaviour regarding the image proportions. + */ + public void setProportions(ProportionsAttribute pa){ + proportions = pa.getValue(); } + /** * Sets the width of the image, either as an integer or a %. Defaults to 100%. */ @@ -117,19 +133,32 @@ pb.addSource(image); float x_fl = getWidth(); float y_fl = getHeight(); + if (!x_percent) { x_fl = (x_fl / image.getWidth()); } if (!y_percent) { y_fl = (y_fl / image.getHeight()); } - if (keep_proportions) { + + if("width".equals(proportions)){ y_fl = x_fl; } + else if("height".equals(proportions)){ + x_fl = y_fl; + } + else if("fit".equals(proportions)){ + x_fl = y_fl = Math.min(x_fl,y_fl); + } + else if("cover".equals(proportions)){ + x_fl = y_fl = Math.max(x_fl,y_fl); + } + pb.add(new Float(x_fl)); pb.add(new Float(y_fl)); - log("\tScaling to " + x_fl + "% x " + y_fl + "%"); + log("\tScaling to " + (x_fl*100) + "% x " + (y_fl*100)+ "%"); + return JAI.create("scale", pb); } 1.2 +5 -5 ant/src/etc/testcases/taskdefs/optional/image/image.xml Index: image.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/image/image.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- image.xml 29 Aug 2002 17:12:17 -0000 1.1 +++ image.xml 22 Aug 2003 09:20:56 -0000 1.2 @@ -18,35 +18,35 @@ <!-- this should produce a single file in the dest dir --> <target name="testSimpleScale" depends="init"> <image includes="*.jpg" srcdir="${src.dir}" destdir="${dest.dir}" overwrite="no" failonerror="no"> - <scale width="300" keepproportions="true"/> + <scale width="300" proportions="width"/> </image> </target> <!-- this should put some text in the log --> <target name="testEchoToLog" depends="init"> <image includes="*.jpg" srcdir="${src.dir}" destdir="${dest.dir}" overwrite="no" failonerror="no"> - <scale width="300" keepproportions="true"/> + <scale width="300" proportions="width"/> </image> </target> <!-- this should produce a single file in the dest dir --> <target name="testFailOnError" depends="init"> <image includes="*.jpg" srcdir="${src.dir}" destdir="${dest.dir}" overwrite="no" failonerror="yes"> - <scale width="300" keepproportions="true"/> + <scale width="300" proportions="width"/> </image> </target> <!-- this should produce a single file in the dest dir, overwriting any existing file --> <target name="testOverwriteTrue" depends="init"> <image includes="*.jpg" srcdir="${src.dir}" destdir="${dest.dir}" overwrite="true" failonerror="no"> - <scale width="300" keepproportions="true"/> + <scale width="300" proportions="width"/> </image> </target> <!-- this should not overwrite the existing file --> <target name="testOverwriteFalse" depends="init"> <image includes="*.jpg" srcdir="${src.dir}" destdir="${dest.dir}" overwrite="false" failonerror="no"> - <scale width="300" keepproportions="true"/> + <scale width="300" proportions="width"/> </image> </target> 1.2 +213 -209 ant/docs/manual/OptionalTasks/image.html Index: image.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/image.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- image.html 16 Apr 2003 12:44:44 -0000 1.1 +++ image.html 22 Aug 2003 09:20:56 -0000 1.2 @@ -1,209 +1,213 @@ -<html> - -<head> -<meta http-equiv="Content-Language" content="en-us"> -<title>Image Task</title> -</head> - -<body> - -<h2><a name="image">Image</a></h2> -<h3>Description</h3> -<p>Applies a chain of image operations on a set of files.</p> -<p>Requires Java Advanced Image API from Sun.</p> - -<h5>Overview of used datatypes</h5> -<img src="image-classdiagram.gif" border="0" alt="Class-Diagram"> - -<h3>Parameters</h3> -<table border="1" cellpadding="2" cellspacing="0"> - <tr> - <td valign="top"><b>Attribute</b></td> - <td valign="top"><b>Description</b></td> - <td align="center" valign="top"><b>Required</b></td> - </tr> - <tr> - <td valign="top"> failonerror </td> - <td valign="top"> Boolean value. If false, note errors to the output but keep going. </td> - <td align="center"> no (defaults to <i>true</i>) </td> - </tr> - <tr> - <td valign="top"> srcdir </td> - <td valign="top"> Directory containing the images. </td> - <td align="center"> yes, unless nested fileset is used </td> - </tr> - <tr> - <td valign="top"> encoding </td> - <td valign="top"> Image encoding type. <br> - Valid (caseinsensitive) are: jpg, jpeg, tif, tiff - </td> - <td align="center"> no (defaults to <i>JPEG</i>) </td> - </tr> - <tr> - <td valign="top"> overwrite </td> - <td valign="top"> Boolean value. Sets whether or not to overwrite - a file if there is naming conflict. - </td> - <td align="center"> no (defaults to <i>false</i>) </td> - </tr> - <tr> - <td valign="top"> gc </td> - <td valign="top"> Boolean value. Enables garbage collection after - each image processed. - </td> - <td align="center"> no (defaults to <i>false</i>) </td> - </tr> - <tr> - <td valign="top"> destdir </td> - <td valign="top"> Directory where the result images are stored. </td> - <td align="center"> no (defaults to value of <i>srcdir</i>) </td> - </tr> - <!-- attributes inherited from MatchingTask --> - <tr> - <td valign="top">includes</td> - <td valign="top">comma- or space-separated list of patterns of files that must be - included. All files are included when omitted.</td> - <td valign="top" align="center">No</td> - </tr> - <tr> - <td valign="top">includesfile</td> - <td valign="top">the name of a file. Each line of this file is - taken to be an include pattern</td> - <td valign="top" align="center">No</td> - </tr> - <tr> - <td valign="top"> excludes</td> - <td valign="top">comma- or space-separated list of patterns of files that must be - excluded. No files (except default excludes) are excluded when omitted.</td> - <td valign="top" align="center">No</td> - </tr> - <tr> - <td valign="top">excludesfile</td> - <td valign="top">the name of a file. Each line of this file is - taken to be an exclude pattern</td> - <td valign="top" align="center">No</td> - </tr> - <tr> - <td valign="top">defaultexcludes</td> - <td valign="top">indicates whether default excludes should be used or not - ("yes"/"no"). Default excludes are used when omitted.</td> - <td valign="top" align="center">No</td> - </tr> - <tr> - <td valign="top"> caseSensitive </td> - <td valign="top"> Boolean value. Sets case sensitivity of the file system. </td> - <td align="center"> no (defaults to <i>false</i>) </td> - </tr> - <tr> - <td valign="top"> followSymlinks </td> - <td valign="top"> Boolean value. Sets whether or not symbolic links hsould be followed. </td> - <td align="center"> no (defaults to <i>true</i>) </td> - </tr> -</table> - -<h3>Parameters specified as nested elements</h3> -<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and -supports all attributes of <code><fileset></code> as well as the -nested <code><include></code>, <code><exclude></code> and -<code><patternset></code> elements.</p> - - -<h4>ImageOperation</h4> -<p>Adds an ImageOperation to chain.</p> -<h5>Nested Elements</h5> -ImageOperation can handle nested Rotate, Draw, Rectangle, Text and Scale objects. - -<h4>Rotate</h4> -<p>Adds a Rotate ImageOperation to chain.</p> -<h5>Parameters</h5> -<table border="1" cellpadding="2" cellspacing="0"> - <tr> - <td valign="top"><b>Attribute</b></td> - <td valign="top"><b>Description</b></td> - <td align="center" valign="top"><b>Required</b></td> - </tr> - <tr> - <td valign="top"> angle </td> - <td valign="top"> Float value. Sets the angle of rotation in degrees. </td> - <td align="center"> no (defaults to <i>0.0F</i>) </td> - </tr> -</table> - -<h4>Scale</h4> -<p>Adds a Scale ImageOperation to chain.</p> -<h5>Parameters</h5> -<table border="1" cellpadding="2" cellspacing="0"> - <tr> - <td valign="top"><b>Attribute</b></td> - <td valign="top"><b>Description</b></td> - <td align="center" valign="top"><b>Required</b></td> - </tr> - <tr> - <td valign="top"> keepproportions </td> - <td valign="top"> Boolean value. Sets whether the proportion heigth/width should be kept. </td> - <td align="center"> no (defaults to <i>false</i>) </td> - </tr> - <tr> - <td valign="top"> width </td> - <td valign="top"> Sets the width of the image, either as an integer or a %. </td> - <!-- todo: if integer, what kind? cm, px, inches, ... --> - <td align="center"> no (defaults to <i>100%</i>) </td> - </tr> - <tr> - <td valign="top"> heigth </td> - <td valign="top"> Sets the height of the image, either as an integer or a %. </td> - <!-- todo: if integer, what kind? cm, px, inches, ... --> - <td align="center"> no (defaults to <i>100%</i>) </td> - </tr> -</table> - -<h4>Draw</h4> -<p>Adds a Draw ImageOperation to chain. DrawOperation DataType objects can be -nested inside the Draw object.</p> -<h5>Parameters</h5> -<table border="1" cellpadding="2" cellspacing="0"> - <tr> - <td valign="top"><b>Attribute</b></td> - <td valign="top"><b>Description</b></td> - <td align="center" valign="top"><b>Required</b></td> - </tr> - <tr> - <td valign="top"> xloc </td> - <td valign="top"> X-Position where to draw nested image elements. </td> - <td align="center"> no (defaults to <i>0</i>) </td> - </tr> - <tr> - <td valign="top"> yloc </td> - <td valign="top"> Y-Position where to draw nested image elements. </td> - <td align="center"> no (defaults to <i>0</i>) </td> - </tr> -</table> - -<h3>Examples</h3> - -<blockquote><pre> -<image srcdir="src" includes="*.png"> - <scale keepproportions="true" width="40"/> -</image> -</pre></blockquote> -<p>Creates a thumbnail for all PNG-files in <i>src</i> in the size of 40 pixel keeping the proportions -and stores the <i>src</i>.</p> - -<blockquote><pre> -<image srcdir="src" destdir="dest" includes="*.png"> - <scale keepproportions="true" width="40"/> -</image> -</pre></blockquote> -<p>Same as above but stores the result in <i>dest</i>.</p> - -<blockquote><pre> -</pre></blockquote> - -<hr> -<p align="center">Copyright © 2003 Apache Software -Foundation. All rights Reserved.</p> - -</body> -</html> - - +<html> + +<head> +<meta http-equiv="Content-Language" content="en-us"> +<title>Image Task</title> +</head> + +<body> + +<h2><a name="image">Image</a></h2> +<h3>Description</h3> +<p>Applies a chain of image operations on a set of files.</p> +<p>Requires Java Advanced Image API from Sun.</p> + +<h5>Overview of used datatypes</h5> +<img src="image-classdiagram.gif" border="0" alt="Class-Diagram"> + +<h3>Parameters</h3> +<table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <tr> + <td valign="top"> failonerror </td> + <td valign="top"> Boolean value. If false, note errors to the output but keep going. </td> + <td align="center"> no (defaults to <i>true</i>) </td> + </tr> + <tr> + <td valign="top"> srcdir </td> + <td valign="top"> Directory containing the images. </td> + <td align="center"> yes, unless nested fileset is used </td> + </tr> + <tr> + <td valign="top"> encoding </td> + <td valign="top"> Image encoding type. <br> + Valid (caseinsensitive) are: jpg, jpeg, tif, tiff + </td> + <td align="center"> no (defaults to <i>JPEG</i>) </td> + </tr> + <tr> + <td valign="top"> overwrite </td> + <td valign="top"> Boolean value. Sets whether or not to overwrite + a file if there is naming conflict. + </td> + <td align="center"> no (defaults to <i>false</i>) </td> + </tr> + <tr> + <td valign="top"> gc </td> + <td valign="top"> Boolean value. Enables garbage collection after + each image processed. + </td> + <td align="center"> no (defaults to <i>false</i>) </td> + </tr> + <tr> + <td valign="top"> destdir </td> + <td valign="top"> Directory where the result images are stored. </td> + <td align="center"> no (defaults to value of <i>srcdir</i>) </td> + </tr> + <!-- attributes inherited from MatchingTask --> + <tr> + <td valign="top">includes</td> + <td valign="top">comma- or space-separated list of patterns of files that must be + included. All files are included when omitted.</td> + <td valign="top" align="center">No</td> + </tr> + <tr> + <td valign="top">includesfile</td> + <td valign="top">the name of a file. Each line of this file is + taken to be an include pattern</td> + <td valign="top" align="center">No</td> + </tr> + <tr> + <td valign="top"> excludes</td> + <td valign="top">comma- or space-separated list of patterns of files that must be + excluded. No files (except default excludes) are excluded when omitted.</td> + <td valign="top" align="center">No</td> + </tr> + <tr> + <td valign="top">excludesfile</td> + <td valign="top">the name of a file. Each line of this file is + taken to be an exclude pattern</td> + <td valign="top" align="center">No</td> + </tr> + <tr> + <td valign="top">defaultexcludes</td> + <td valign="top">indicates whether default excludes should be used or not + ("yes"/"no"). Default excludes are used when omitted.</td> + <td valign="top" align="center">No</td> + </tr> + <tr> + <td valign="top"> caseSensitive </td> + <td valign="top"> Boolean value. Sets case sensitivity of the file system. </td> + <td align="center"> no (defaults to <i>false</i>) </td> + </tr> + <tr> + <td valign="top"> followSymlinks </td> + <td valign="top"> Boolean value. Sets whether or not symbolic links hsould be followed. </td> + <td align="center"> no (defaults to <i>true</i>) </td> + </tr> +</table> + +<h3>Parameters specified as nested elements</h3> +<p>This task forms an implicit <a href="../CoreTypes/fileset.html">FileSet</a> and +supports all attributes of <code><fileset></code> as well as the +nested <code><include></code>, <code><exclude></code> and +<code><patternset></code> elements.</p> + + +<h4>ImageOperation</h4> +<p>Adds an ImageOperation to chain.</p> +<h5>Nested Elements</h5> +ImageOperation can handle nested Rotate, Draw, Rectangle, Text and Scale objects. + +<h4>Rotate</h4> +<p>Adds a Rotate ImageOperation to chain.</p> +<h5>Parameters</h5> +<table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <tr> + <td valign="top"> angle </td> + <td valign="top"> Float value. Sets the angle of rotation in degrees. </td> + <td align="center"> no (defaults to <i>0.0F</i>) </td> + </tr> +</table> + +<h4>Scale</h4> +<p>Adds a Scale ImageOperation to chain.</p> +<h5>Parameters</h5> +<table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <td valign="top"> proportions </td> + <td valign="top"> Sets which dimension to control proportions from. Valid values are:<ul> + <li>"ignore" - treat the dimensions independently.</li> + <li>"height" - keep proportions based on the width.</li> + <li>"width" - keep proportions based on the height.</li> + <li>"cover" - keep proportions and fit in the supplied dimensions.</li> + <li>"fit" - keep proportions and cover the supplied dimensions.</li> + </ul></td> ++ <td align="center"> no (defaults to <i>ignore</i>) </td> + <tr> + <td valign="top"> width </td> + <td valign="top"> Sets the width of the image, either as an integer or a %. </td> + <!-- todo: if integer, what kind? cm, px, inches, ... --> + <td align="center"> no (defaults to <i>100%</i>) </td> + </tr> + <tr> + <td valign="top"> heigth </td> + <td valign="top"> Sets the height of the image, either as an integer or a %. </td> + <!-- todo: if integer, what kind? cm, px, inches, ... --> + <td align="center"> no (defaults to <i>100%</i>) </td> + </tr> +</table> + +<h4>Draw</h4> +<p>Adds a Draw ImageOperation to chain. DrawOperation DataType objects can be +nested inside the Draw object.</p> +<h5>Parameters</h5> +<table border="1" cellpadding="2" cellspacing="0"> + <tr> + <td valign="top"><b>Attribute</b></td> + <td valign="top"><b>Description</b></td> + <td align="center" valign="top"><b>Required</b></td> + </tr> + <tr> + <td valign="top"> xloc </td> + <td valign="top"> X-Position where to draw nested image elements. </td> + <td align="center"> no (defaults to <i>0</i>) </td> + </tr> + <tr> + <td valign="top"> yloc </td> + <td valign="top"> Y-Position where to draw nested image elements. </td> + <td align="center"> no (defaults to <i>0</i>) </td> + </tr> +</table> + +<h3>Examples</h3> + +<blockquote><pre> +<image srcdir="src" includes="*.png"> + <scale keepproportions="true" width="40"/> +</image> +</pre></blockquote> +<p>Creates a thumbnail for all PNG-files in <i>src</i> in the size of 40 pixel keeping the proportions +and stores the <i>src</i>.</p> + +<blockquote><pre> +<image srcdir="src" destdir="dest" includes="*.png"> + <scale keepproportions="true" width="40"/> +</image> +</pre></blockquote> +<p>Same as above but stores the result in <i>dest</i>.</p> + +<blockquote><pre> +</pre></blockquote> + +<hr> +<p align="center">Copyright © 2003 Apache Software +Foundation. All rights Reserved.</p> + +</body> +</html> + +
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]