From: <fg...@us...> - 2011-01-23 17:56:22
|
Revision: 3258 http://openutils.svn.sourceforge.net/openutils/?rev=3258&view=rev Author: fgiust Date: 2011-01-23 17:56:15 +0000 (Sun, 23 Jan 2011) Log Message: ----------- MEDIA-195 In images resulting from fitbands resize sometimes there is a black line between image and band (left side or bottom side) Modified Paths: -------------- trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 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 2011-01-21 13:40:40 UTC (rev 3257) +++ trunk/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/ImageUtils.java 2011-01-23 17:56:15 UTC (rev 3258) @@ -351,16 +351,16 @@ * Save a resolution for an image to a node (in resolutions/res-[width]x[height]/data.jpg) * @param image image to save * @param saveTo node to save to - * @param outputformat extension + * @param extension extension * @param quality image quality * @param forceProgressive true to force progressive mode * @throws RepositoryException exception in jcr operations * @throws IOException exception converting image to jpg */ - public static void saveResolution(BufferedImage image, Content saveTo, String outputformat, float quality, + public static void saveResolution(BufferedImage image, Content saveTo, String extension, float quality, boolean forceProgressive) throws RepositoryException, IOException { - saveResolution(image, saveTo, null, outputformat, quality, forceProgressive); + saveResolution(image, saveTo, null, extension, quality, forceProgressive); } /** @@ -368,13 +368,13 @@ * @param image image to save * @param saveTo node to save to * @param name name for this resolution - * @param outputformat extension + * @param extension extension * @param quality image quality * @param forceProgressive true to force progressive mode * @throws RepositoryException exception in jcr operations * @throws IOException exception converting image to jpg */ - public static void saveResolution(BufferedImage image, Content saveTo, String name, String outputformat, + public static void saveResolution(BufferedImage image, Content saveTo, String name, String extension, float quality, boolean forceProgressive) throws RepositoryException, IOException { @@ -382,7 +382,7 @@ try { - stream = new CountBytesBufferedInputStream(getStream(image, outputformat, quality, forceProgressive)); + stream = new CountBytesBufferedInputStream(getStream(image, extension, quality, forceProgressive)); if (stream == null) { @@ -419,20 +419,23 @@ log.info("setting value to {}", nd.getHandle()); nd.setValue(stream); - String mimetype = "image/" + outputformat; - if ("jpg".equals(outputformat)) + String mimetype = "image/" + extension; + if ("jpg".equals(extension)) { mimetype = "image/jpeg"; } nd.setAttribute(ImageUtils.RESOLUTION_PROPERTY, originalRes); - nd.setAttribute(FileProperties.PROPERTY_EXTENSION, outputformat); + nd.setAttribute(FileProperties.PROPERTY_EXTENSION, extension); nd.setAttribute(FileProperties.PROPERTY_FILENAME, saveTo.getName()); nd.setAttribute(FileProperties.PROPERTY_CONTENTTYPE, mimetype); - nd.setAttribute(FileProperties.PROPERTY_LASTMODIFIED, GregorianCalendar.getInstance(TimeZone - .getDefault())); + nd.setAttribute( + FileProperties.PROPERTY_LASTMODIFIED, + GregorianCalendar.getInstance(TimeZone.getDefault())); nd.setAttribute(FileProperties.PROPERTY_WIDTH, "" + image.getWidth()); nd.setAttribute(FileProperties.PROPERTY_HEIGHT, "" + image.getHeight()); + nd.setAttribute(FileProperties.PROPERTY_SIZE, "" + stream.getCount()); + } } finally @@ -528,7 +531,7 @@ } else { - params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_COPY_FROM_METADATA); + params.setProgressiveMode(javax.imageio.ImageWriteParam.MODE_DISABLED); } } catch (UnsupportedOperationException e) @@ -597,7 +600,7 @@ /** * Check if the resolution for a media is already present. Otherwise create it - * @param media media to check the resolution on + * @param media media to check the resolutoin on * @param resolutionTarget target resolution * @return false if resolution doesn't exist and there is a problem in generate it; true otherwise */ @@ -609,7 +612,7 @@ /** * Check if the resolution for a media is already present. Otherwise create it - * @param media media to check the resolutoin on + * @param media media to check the resolution on * @param resolutionTarget target resolution * @param nodeDataName nodedata where the image to resize is stored * @return false if resolution doesn't exist and there is a problem in generate it; true otherwise @@ -715,10 +718,18 @@ + image.getContentLength()); } - String outputextension = image.getAttribute(FileProperties.PROPERTY_EXTENSION); - if (!Arrays.asList(extensions).contains(outputextension)) + String extension = image.getAttribute(FileProperties.PROPERTY_EXTENSION); + if (!Arrays.asList(extensions).contains(extension)) { - outputextension = "png"; + try + { + image.setAttribute(FileProperties.PROPERTY_EXTENSION, "jpg"); + } + catch (RepositoryException e) + { + throw new RuntimeException(e); + } + extension = "jpg"; } BufferedImage original = createBufferedImage(image); @@ -762,23 +773,12 @@ } if ("thumbnail".equals(resolutionTarget) || "preview".equals(resolutionTarget)) { - ImageUtils.saveResolution( - img, - node, - resolutionTarget, - outputextension, - quality, - forceProgressive); + ImageUtils + .saveResolution(img, node, resolutionTarget, extension, quality, forceProgressive); } else { - ImageUtils.saveResolution( - img, - node, - resolutionName, - outputextension, - quality, - forceProgressive); + ImageUtils.saveResolution(img, node, resolutionName, extension, quality, forceProgressive); } } catch (RepositoryException e) @@ -895,11 +895,10 @@ if (ImageProcessorsManager.getInstance().isValidControlChar(controlChar)) { - img = ImageProcessorsManager.getInstance().getImageResolutionProcessor(controlChar).getImageForResolution( - original, - size.x, - size.y, - params); + img = ImageProcessorsManager + .getInstance() + .getImageResolutionProcessor(controlChar) + .getImageForResolution(original, size.x, size.y, params); } else if (controlChar < '0' || controlChar > '9') { @@ -907,11 +906,10 @@ } else { - img = ImageProcessorsManager.getInstance().getDefaultImageResolutionProcessor().getImageForResolution( - original, - size.x, - size.y, - params); + img = ImageProcessorsManager + .getInstance() + .getDefaultImageResolutionProcessor() + .getImageForResolution(original, size.x, size.y, params); } for (ImagePostProcessor ipp : ImageProcessorsManager.getInstance().getImagePostProcessorsList()) @@ -952,40 +950,22 @@ InputStream is = image.getStream(); try { + return ImageIO.read(is); + } + catch (IOException e) + { + // CMYK jpeg can't be read be ImageIO + // Caused by: javax.imageio.IIOException: Unsupported Image Type + BufferedImage result = JpegUtils.processNonStandardImage(image); - String ext = image.getAttribute(FileProperties.EXTENSION); - - if (StringUtils.equalsIgnoreCase(ext, "jpg") || StringUtils.equalsIgnoreCase(ext, "jpeg")) + if (result == null) { - try - { - return JpegUtils.processNonStandardImage(image); - } - catch (Throwable e) - { - // sun classes may not be available or other errors occurred, try with the standard ImageIO - log - .debug( - "Unable to process image " + image.getHandle() + " using JpegUtils: " + e.getMessage(), - e); - } + // throw the original exception back + throw new BadImageFormatException("Unable to handle " + image.getHandle(), e); } - else if (StringUtils.equalsIgnoreCase(ext, "ico") || StringUtils.equalsIgnoreCase(ext, "bmp")) - { - BufferedImage buffered = IcoUtils.createBufferedImage(image); - if (buffered != null) - { - return buffered; - } - } + return result; - return ImageIO.read(is); } - catch (IOException e) - { - // throw the original exception back - throw new BadImageFormatException("Unable to handle " + image.getHandle(), e); - } finally { IOUtils.closeQuietly(is); @@ -993,7 +973,7 @@ } /** - * Parse resolution string for required size + * Parse resolution string for required sizesuper.read(b); * @param res resolution string * @return required size parsed from given resolution string */ @@ -1083,5 +1063,4 @@ } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |