From: <fg...@us...> - 2009-08-12 16:20:54
|
Revision: 1256 http://openutils.svn.sourceforge.net/openutils/?rev=1256&view=rev Author: fgiust Date: 2009-08-12 16:20:46 +0000 (Wed, 12 Aug 2009) Log Message: ----------- Avoid image processing when the requested size is identical to the original image Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java trunk/openutils-mgnlmedia/src/site/changes/changes.xml Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java 2009-08-12 14:26:58 UTC (rev 1255) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/tags/el/MediaEl.java 2009-08-12 16:20:46 UTC (rev 1256) @@ -24,6 +24,7 @@ import info.magnolia.cms.util.NodeDataUtil; import info.magnolia.context.MgnlContext; +import java.awt.Point; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -273,6 +274,15 @@ */ public static String getResolutionUrl(Content media, String resolution) { + FileProperties prop = new FileProperties(media, "image"); + Integer width = NumberUtils.toInt(prop.getProperty(FileProperties.PROPERTY_WIDTH)); + Integer height = NumberUtils.toInt(prop.getProperty(FileProperties.PROPERTY_HEIGHT)); + Point size = ImageUtils.parseForSize(resolution); + if (width == size.x && height == size.y) + { + return mcm.getURIMappingPrefix() + prop.getProperty(FileProperties.PATH); + } + if (media == null || !ImageUtils.checkOrCreateResolution(media, resolution)) { return null; Modified: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-08-12 14:26:58 UTC (rev 1255) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-08-12 16:20:46 UTC (rev 1256) @@ -1,3 +1,5 @@ +package net.sourceforge.openutils.mgnlmedia.media.utils; + /** * Copyright Openmind http://www.openmindonline.it * @@ -15,7 +17,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ -package net.sourceforge.openutils.mgnlmedia.media.utils; import info.magnolia.cms.beans.runtime.FileProperties; import info.magnolia.cms.core.Content; @@ -27,6 +28,7 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; +import java.awt.Point; import java.awt.RenderingHints; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; @@ -254,6 +256,13 @@ double xRatio = (double) x / oX; double yRatio = (double) y / oY; + + if (xRatio * yRatio == 1) + { + log.debug("Nothing to resize, return original"); + return original; + } + double ratio = Math.min(xRatio, yRatio); int newX = (int) Math.round(oX * ratio); int newY = (int) Math.round(oY * ratio); @@ -289,7 +298,8 @@ } else { - return resizeImage(original, x, y); + return original; + // return resizeImage(original, x, y); } } @@ -654,20 +664,14 @@ String controlChar = StringUtils.substring(resolution, 0, 1); + Point size = parseForSize(resolution); + if ("<".equals(controlChar) || "l".equals(controlChar)) { - String resx = resolution.startsWith("<") ? StringUtils.substringBefore(StringUtils.substringAfter( - resolution, - "<"), "x") : StringUtils.substringBefore(StringUtils.substringAfter(resolution, "l"), "x"); - String resy = StringUtils.substringAfter(resolution, "x"); - - img = fitIn(original, NumberUtils.toInt(resx), NumberUtils.toInt(resy)); + img = fitIn(original, size.x, size.y); } else if (resolution.startsWith("o")) { - String resx = StringUtils.substringBefore(StringUtils.substringAfter(resolution, "o"), "x"); - String resy = StringUtils.substringAfter(resolution, "x"); - Color background = null; if (StringUtils.contains(params, "background=")) @@ -682,21 +686,12 @@ log.error("Invalid color code: " + colorHex, e); } } - - img = resizeNoCrop(original, NumberUtils.toInt(resx), NumberUtils.toInt(resy), background); + img = resizeNoCrop(original, size.x, size.y, background); } else { - String resx = StringUtils.substringBefore(resolution, "x"); - String resy = StringUtils.substringAfter(resolution, "x"); - - if (resx.charAt(0) < '0' || resx.charAt(0) > '9') - { - resx = resx.substring(1); - } - - img = fillAndCropCentered(original, NumberUtils.toInt(resx), NumberUtils.toInt(resy)); + img = fillAndCropCentered(original, size.x, size.y); } return img; @@ -747,4 +742,43 @@ } } + public static java.awt.Point parseForSize(String res) + { + Point size = new Point(); + String resolution = StringUtils.lowerCase(res); + String resx, resy; + + if (StringUtils.contains(resolution, ";")) + { + resolution = StringUtils.substringBefore(resolution, ";"); + } + String controlChar = StringUtils.substring(resolution, 0, 1); + + if ("<".equals(controlChar) || "l".equals(controlChar)) + { + resx = resolution.startsWith("<") ? StringUtils.substringBefore( + StringUtils.substringAfter(resolution, "<"), + "x") : StringUtils.substringBefore(StringUtils.substringAfter(resolution, "l"), "x"); + resy = StringUtils.substringAfter(resolution, "x"); + } + else if (resolution.startsWith("o")) + { + resx = StringUtils.substringBefore(StringUtils.substringAfter(resolution, "o"), "x"); + resy = StringUtils.substringAfter(resolution, "x"); + } + else + { + resx = StringUtils.substringBefore(resolution, "x"); + resy = StringUtils.substringAfter(resolution, "x"); + + if (resx.charAt(0) < '0' || resx.charAt(0) > '9') + { + resx = resx.substring(1); + } + } + size.x = NumberUtils.toInt(resx); + size.y = NumberUtils.toInt(resy); + return size; + } + } Modified: trunk/openutils-mgnlmedia/src/site/changes/changes.xml =================================================================== --- trunk/openutils-mgnlmedia/src/site/changes/changes.xml 2009-08-12 14:26:58 UTC (rev 1255) +++ trunk/openutils-mgnlmedia/src/site/changes/changes.xml 2009-08-12 16:20:46 UTC (rev 1256) @@ -8,6 +8,10 @@ <author email="fgiust(at)users.sourceforge.net">Fabrizio Giustina</author> </properties> <body> + <release version="4.0-b6" date="in svn" description=""> + <action type="fix" dev="fgiust">Avoid image processing when the requested size is identical to the original image + </action> + </release> <release version="4.0-b5" date="2009-06-04" description=""> <action type="fix" dev="fgiust">MediaCustomSaveHandler now only warns about missing referenced media without blocking</action> @@ -28,7 +32,8 @@ <action type="update" dev="fgiust">Update openutils-mgnltasks dependency to 4.0</action> <action type="add" dev="fgiust">Support for resize without crop to a fixed size with borders. Background color can be specified with the syntax: "o100x100;background=FF0096"</action> - <action type="add" dev="fgiust">Alternative prefix for "fit in" resize. In previous versions you had to use < (not very handy in html), now you can use "L" (lower, case insensitive), e.g. "L100x100"</action> + <action type="add" dev="fgiust">Alternative prefix for "fit in" resize. In previous versions you had to use < + (not very handy in html), now you can use "L" (lower, case insensitive), e.g. "L100x100"</action> </release> <release version="4.0-b2" date="2009-04-16" description=""> <action type="update" dev="fgiust">Stable release for Magnolia 4.x</action> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |