cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anathan...@apache.org
Subject svn commit: r674971 - /cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java
Date Tue, 08 Jul 2008 21:38:56 GMT
Author: anathaniel
Date: Tue Jul  8 14:38:56 2008
New Revision: 674971

URL: http://svn.apache.org/viewvc?rev=674971&view=rev
Log:
    <action dev="AN" type="fix" fixes-bug="COCOON-2169" due-to="Mark Lundquist" due-to-email="lundquist.mark@gmail.com">
      ImageOp block: If parameter width or height in resize operation is zero, use the original
image size.
      If both are zero, then handle as no-op.  Set default values to zero to allow using that
feature by
      leaving out the parameters.
    </action>

Modified:
    cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java

Modified: cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java?rev=674971&r1=674970&r2=674971&view=diff
==============================================================================
--- cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java
(original)
+++ cocoon/trunk/blocks/cocoon-imageop/cocoon-imageop-impl/src/main/java/org/apache/cocoon/reading/imageop/ResizeOperation.java
Tue Jul  8 14:38:56 2008
@@ -40,11 +40,11 @@
     public void setup( Parameters params )
     throws ProcessingException {
         enabled = params.getParameterAsBoolean( prefix + "enabled", true);
-        height = params.getParameterAsInteger( prefix + "height", 200 );
+        height = params.getParameterAsInteger( prefix + "height", 0 );
         if( height < 0 ) {
             throw new ProcessingException( "Negative Height is not allowed: " + height );
         }
-        width = params.getParameterAsInteger( prefix + "width", 300 );
+        width = params.getParameterAsInteger( prefix + "width", 0 );
         if( width < 0 ) {
             throw new ProcessingException( "Negative Width is not allowed: " + width );
         }
@@ -57,13 +57,17 @@
         if( ! enabled ) {
             return image;
         }
-        if ( this.width == 0 && this.height == 0 ) {
+
+        // If parameter width or height is zero, use the original image size.
+        // Therefore, if both are zero, the image is returned unchanged.
+
+        if ( width == 0 && height == 0 ) {
             return image;
         }
-        double height = image.getHeight();
-        double width = image.getWidth();
-        double xScale = this.width / width;
-        double yScale = this.height / height;
+
+        double xScale = width == 0 ? 1 : width / (double) image.getWidth();
+        double yScale = height == 0 ? 1 : height / (double) image.getHeight();
+
         if (allowEnlarge || (xScale <= 1 && yScale <= 1))
         {
 	        if( preserveRatio )



Mime
View raw message