Class ImageHelper

  • Direct Known Subclasses:
    ImageHelper

    public class ImageHelper
    extends java.lang.Object
    ImageHelper...
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Layer createLayer​(Item item)
      Creates a layer of the given item.
      static Layer createLayer​(Node node, java.lang.String imageName, java.lang.String refName)
      Creates a layer either by the node addressed by imageName or the referenced image addressed by the refName property.
      static Layer createLayer​(Session session, java.lang.String path)
      Creates a layer of the given item addressed by the path.
      static Layer createLayer​(Resource resource)
      Creates a layer from the given resource.
      static java.awt.Rectangle getCropRect​(java.lang.String rectCSV, java.lang.String path)
      d Parses a CSV string of the form "x1,y1,x2,y2" and returns the respective rectangle.
      static java.lang.String getExtensionFromType​(java.lang.String type)
      Returns the extension from the given image type.
      static java.lang.String getTypeFromExtension​(java.lang.String ext)
      Returns the image type for the given extension.
      static java.awt.Color parseColor​(java.lang.String s)
      Converts a String to an integer and returns the specified Color.
      static java.awt.Color parseColor​(java.lang.String s, int alpha)
      Converts a String to an integer and returns the specified Color.
      static int parseFontStyle​(java.lang.String... styles)
      Parses the font style from the given string(s).
      static Layer resize​(Layer layer, java.awt.Dimension d, java.awt.Dimension min, java.awt.Dimension max)
      Resizes the given layer according to the given dimensions.
      static Node saveLayer​(Layer layer, java.lang.String type, double quality, Node parent, java.lang.String filename, boolean replace)
      Saves the layer as nt:file below the given node.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ImageHelper

        public ImageHelper()
    • Method Detail

      • getCropRect

        public static java.awt.Rectangle getCropRect​(java.lang.String rectCSV,
                                                     java.lang.String path)
        d Parses a CSV string of the form "x1,y1,x2,y2" and returns the respective rectangle. if the string could not be parsed, null is returned. The method can deal with an aspect ratio that is appended by "/" (e.g. "x1,y1,x2,y2/ratioX,ratioY".
        Parameters:
        rectCSV - the rectangle coordinates
        path - optional path for debugging
        Returns:
        a rectangle or null
      • createLayer

        public static Layer createLayer​(Node node,
                                        java.lang.String imageName,
                                        java.lang.String refName)
                                 throws RepositoryException,
                                        java.io.IOException
        Creates a layer either by the node addressed by imageName or the referenced image addressed by the refName property.
        Parameters:
        node - the current node
        imageName - the name of the image node
        refName - the name of the reference property
        Returns:
        a layer or null
        Throws:
        RepositoryException - if a repository error occurs
        java.io.IOException - if a I/O error occurs
      • createLayer

        public static Layer createLayer​(Session session,
                                        java.lang.String path)
                                 throws RepositoryException,
                                        java.io.IOException
        Creates a layer of the given item addressed by the path. the item can be a binary property, a nt:file node or a nt:resource node.
        Parameters:
        session - to use for retrieving the item
        path - to the item
        Returns:
        a layer or null
        Throws:
        RepositoryException - if a repository error occurs
        java.io.IOException - if a I/O error occurs
      • createLayer

        public static Layer createLayer​(Resource resource)
        Creates a layer from the given resource. If the resource is not adaptable to InputStream null is returned.
        Parameters:
        resource - resource
        Returns:
        layer or null
      • createLayer

        public static Layer createLayer​(Item item)
                                 throws RepositoryException,
                                        java.io.IOException
        Creates a layer of the given item. the item can be a binary property, a nt:file node or a nt:resource node.
        Parameters:
        item - the item
        Returns:
        a layer or null
        Throws:
        RepositoryException - if a repository error occurs
        java.io.IOException - if a I/O error occurs
      • resize

        public static Layer resize​(Layer layer,
                                   java.awt.Dimension d,
                                   java.awt.Dimension min,
                                   java.awt.Dimension max)
        Resizes the given layer according to the given dimensions. If both width and height are defined a non-proportional resizing is done. if one of the dimensions is missing or 0, a proportional resizing performed. the non-empty dimensions are trimmed to respect the minimal and maximal dimension constraints. for proportional resizing the constraints apply to the recalculated dimensions. when no dimensions are specified, the layer is resized to fit into the constraint dimensions accordingly. if the constraints cannot be applied to the dimensions, eg if no values can be found that match the constraints, the layer is left untouched. In any case, if no resizing is performed, null is returned. Examples:
         | lW  | lH  | dW  | dH  | minW | maxW | minH | maxH | w   | h   | comment               |
         |     |     | 400 | 200 |    0 |    0 |    0 |    0 | 400 | 200 | no resizing           |
         |     |     | 400 | 200 |    0 |  200 |    0 |    0 | 200 | 100 | 200 max width applies |
         | 120 |  80 |   0 |   0 |  100 |  400 |   50 |  100 | 120 |  80 | within bounds         |
         | 120 |  80 |   0 |   0 |    0 |  100 |   50 |  100 | 100 |  60 | 100 max width applies |
         | 400 | 100 | 300 |   0 |    0 |    0 |    0 |    0 | 300 |  75 | resize proportional   |
         | 400 | 100 | 300 |   0 |    0 |    0 |    0 |   50 | 200 |  50 | max height applies    |
         
        Parameters:
        layer - layer to resize.
        d - dimension
        min - minimal dimension constraints
        max - maximal dimension constraints
        Returns:
        the resized layer or null if untouched.
      • parseColor

        public static java.awt.Color parseColor​(java.lang.String s)
        Converts a String to an integer and returns the specified Color. This method handles string formats that are used to represent octal and hexadecimal numbers. If the string cannot be converted an transparent black is returned.
        Parameters:
        s - a String that represents an RGBA color as a 32-bit integer
        Returns:
        the new Color object.
        See Also:
        Integer.decode(java.lang.String)
      • parseColor

        public static java.awt.Color parseColor​(java.lang.String s,
                                                int alpha)
        Converts a String to an integer and returns the specified Color. This method handles string formats that are used to represent octal and hexadecimal numbers. If the string cannot be converted an transparent black is returned.
        Parameters:
        s - a String that represents an RGB color as a 24-bit integer
        alpha - override the alpha setting
        Returns:
        the new Color object.
        See Also:
        Integer.decode(java.lang.String)
      • saveLayer

        public static Node saveLayer​(Layer layer,
                                     java.lang.String type,
                                     double quality,
                                     Node parent,
                                     java.lang.String filename,
                                     boolean replace)
                              throws RepositoryException,
                                     java.io.IOException
        Saves the layer as nt:file below the given node.
        Parameters:
        layer - the layer to save
        type - image type. eg "image/png"
        quality - image quality. eg 1.0
        parent - parent node
        filename - file name
        replace - if true existing node are replaced rather than updated.
        Returns:
        the newly created and saved file node
        Throws:
        RepositoryException - if a repository error occurrs
        java.io.IOException - if an I/O error occurrs
      • getTypeFromExtension

        public static java.lang.String getTypeFromExtension​(java.lang.String ext)
        Returns the image type for the given extension. currently there are only "png", "gif", "jpeg" and "jpg" supported.
        Parameters:
        ext - the extension
        Returns:
        the image type or null.
      • getExtensionFromType

        public static java.lang.String getExtensionFromType​(java.lang.String type)
        Returns the extension from the given image type. currently there are only "png", "gif", "jpeg" and "jpg" supported.
        Parameters:
        type - the mime type
        Returns:
        the extension or null.