Is there some problem with http://issues.apache.org/bugzilla/post_bug.cgi? I wasn't able to create a bug in buzilla so for now I've had another go at attaching the patch using .txt extension this time.
I've also patched the .html although the (huge!) class diagram image is now out of date. Rob ----- Original Message ----- From: "Antoine Levy-Lambert" <[EMAIL PROTECTED]> To: "Ant Developers List" <[EMAIL PROTECTED]> Sent: Thursday, August 21, 2003 7:08 PM Subject: Re: [PATCH] Image scaling > Rob : > can you please create a bugzilla report with your patch ? > I could not read you attachment anyway. > Also include in your patch the docu if possible. > Thanks in advance. > Antoine > ----- Original Message ----- > From: "Rob Oxspring" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, August 21, 2003 7:58 PM > Subject: [PATCH] Image scaling > > > First up, sorry for no unit tests - just doing enough to get by for now :) > > Anyway, 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 has been added with the following features: > > proportions="ignore" - treat the dimensions independantly > (==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 > > So for example I can use the following to create thumbnails of my images and > make sure they all fit within the 160x160 size whether the image is portrait > or landscape. > > <image destdir="samples/low" overwrite="yes"> > <fileset dir="samples/full"> > <filename name="**/*.jpg"/> > </fileset> > <scale width="160" height="160" proportions="fit"/> > </image> > > Hope that's helpful to others, > > Rob > > > > > ---------------------------------------------------------------------------- > ---- > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
Index: docs/manual/OptionalTasks/image.html =================================================================== RCS file: /home/cvspublic/ant/docs/manual/OptionalTasks/image.html,v retrieving revision 1.1 diff -u -r1.1 image.html --- docs/manual/OptionalTasks/image.html 16 Apr 2003 12:44:44 -0000 1.1 +++ docs/manual/OptionalTasks/image.html 21 Aug 2003 23:57:46 -0000 @@ -139,9 +139,15 @@ <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> + <td valign="top"> proportions </td> + <td valign="top"> Sets which dimension to control proportions from. Valid values are:<ul> + <li>"ignore" - treat the dimensions independantly.</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> <tr> <td valign="top"> width </td> @@ -150,7 +156,7 @@ <td align="center"> no (defaults to <i>100%</i>) </td> </tr> <tr> - <td valign="top"> heigth </td> + <td valign="top"> height </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> Index: src/main/org/apache/tools/ant/types/optional/image/Scale.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/types/optional/image/Scale.java,v retrieving revision 1.5 diff -u -r1.5 Scale.java --- src/main/org/apache/tools/ant/types/optional/image/Scale.java 22 Apr 2003 07:35:17 -0000 1.5 +++ src/main/org/apache/tools/ant/types/optional/image/Scale.java 21 Aug 2003 23:57:53 -0000 @@ -53,8 +53,12 @@ */ 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; @@ -64,15 +68,26 @@ * @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 +132,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); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]