From: <mol...@us...> - 2009-10-08 15:39:25
|
Revision: 1477 http://openutils.svn.sourceforge.net/openutils/?rev=1477&view=rev Author: molaschi Date: 2009-10-08 15:39:13 +0000 (Thu, 08 Oct 2009) Log Message: ----------- MEDIA-26 rounded corners image processor Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java Added Paths: ----------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/processors/RoundedCornersProcessor.java trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.processors.image-post.rc.xml Added: trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/processors/RoundedCornersProcessor.java =================================================================== --- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/processors/RoundedCornersProcessor.java (rev 0) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/processors/RoundedCornersProcessor.java 2009-10-08 15:39:13 UTC (rev 1477) @@ -0,0 +1,60 @@ +package net.sourceforge.openutils.mgnlmedia.media.processors; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.util.Map; + +import net.sourceforge.openutils.mgnlmedia.media.utils.ImageUtils; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.math.NumberUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author molaschi + * @version $Id: $ + */ +public class RoundedCornersProcessor implements ImagePostProcessor +{ + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(RoundedCornersProcessor.class); + + /** + * {@inheritDoc} + */ + public BufferedImage processImage(BufferedImage image, int x, int y, Map<String, String> parameters) + { + String roundCorners = parameters.get("roundcorners"); + if (StringUtils.isNotBlank(roundCorners)) + { + int radius = 5; + if (!"true".equals(roundCorners)) + { + radius = NumberUtils.toInt(roundCorners); + } + + Color backgroundColor = null; + String hexColor = parameters.get("background"); + if (StringUtils.isNotBlank(hexColor)) + { + try + { + hexColor = "0x" + (hexColor.startsWith("#") ? hexColor.substring(1) : hexColor); + backgroundColor = Color.decode(hexColor); + } + catch (NumberFormatException e) + { + log.error("Invalid color code: " + hexColor, e); + } + } + return ImageUtils.addRoundedCorners(image, backgroundColor, radius); + } + return image; + } + +} 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-10-08 15:19:54 UTC (rev 1476) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2009-10-08 15:39:13 UTC (rev 1477) @@ -290,7 +290,7 @@ return rgb; } - public static BufferedImage addRoundedCorners(BufferedImage original, String backgroundColor, int radius) + public static BufferedImage addRoundedCorners(BufferedImage original, Color backgroundColor, int radius) { BufferedImage resizedImage; try @@ -307,10 +307,15 @@ graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); - int[] colorAr = convertHexToRGB(backgroundColor); - Color color = new Color(colorAr[0], colorAr[1], colorAr[2], colorAr[3]); + if (original.getColorModel().getTransparency() == Transparency.OPAQUE && backgroundColor == null) + { + backgroundColor = Color.WHITE; + } + if (backgroundColor != null) + { + graphics2D.setBackground(backgroundColor); + } - graphics2D.setBackground(color); graphics2D.clearRect(0, 0, original.getWidth(), original.getHeight()); graphics2D .setClip(new RoundRectangle2D.Double(0, 0, original.getWidth(), original.getHeight(), radius, radius)); Added: trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.processors.image-post.rc.xml =================================================================== --- trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.processors.image-post.rc.xml (rev 0) +++ trunk/openutils-mgnlmedia/src/main/resources/mgnl-bootstrap/media/config.modules.media.processors.image-post.rc.xml 2009-10-08 15:39:13 UTC (rev 1477) @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<sv:node sv:name="bw" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" + xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" + xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:w10="urn:schemas-microsoft-com:office:word" + xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:html="http://www.w3.org/TR/REC-html40" + xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:v="urn:schemas-microsoft-com:vml" + xmlns:mgnl="http://www.magnolia.info/jcr/mgnl" xmlns:jcrfn="http://www.jcp.org/jcr/xpath-functions/1.0" + xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:rep="internal" xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:stringutils="xalan://org.apache.commons.lang.StringUtils" + xmlns:_pre="urn:schemas-microsoft-com:office:spreadsheet" + xmlns:jcrutils="xalan://it.openmindonline.urmetdomus.assembler.utils.Path" + xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" + xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" + xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" + xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>mgnl:contentNode</sv:value> + </sv:property> + <sv:property sv:name="jcr:mixinTypes" sv:type="Name"> + <sv:value>mix:lockable</sv:value> + </sv:property> + <sv:property sv:name="jcr:uuid" sv:type="String"> + <sv:value>fc6d140b-2133-4abc-b30b-5d4a76e9424b</sv:value> + </sv:property> + <sv:property sv:name="class" sv:type="String"> + <sv:value>net.sourceforge.openutils.mgnlmedia.media.processors.RoundedCornersProcessor</sv:value> + </sv:property> + <sv:node sv:name="MetaData"> + <sv:property sv:name="jcr:primaryType" sv:type="Name"> + <sv:value>mgnl:metaData</sv:value> + </sv:property> + <sv:property sv:name="mgnl:activated" sv:type="Boolean"> + <sv:value>false</sv:value> + </sv:property> + <sv:property sv:name="mgnl:authorid" sv:type="String"> + <sv:value>superuser</sv:value> + </sv:property> + <sv:property sv:name="mgnl:creationdate" sv:type="Date"> + <sv:value>2009-09-03T18:28:30.446+02:00</sv:value> + </sv:property> + <sv:property sv:name="mgnl:lastmodified" sv:type="Date"> + <sv:value>2009-09-09T10:15:47.224+02:00</sv:value> + </sv:property> + </sv:node> +</sv:node> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |