Class ImageHelper


  • @Scriptable
    public final class ImageHelper
    extends Object
    • Method Detail

      • getImageFormat

        public static IMAGE_FORMAT getImageFormat​(Object p_file)
        Get the image format of the given file.

        Currently the image format is derived from the file extension.

        Parameters:
        p_file - The image file (a File, a Path, or a character sequence).
        Returns:
        The image format, or null if it could not be derived from the file extension.
      • isSupportedImageFormat

        public static boolean isSupportedImageFormat​(Object p_file)
        Check if the given file has a supported image format.

        Currently PNG, JPEG, and BMP are supported, and this method only checks for well-known file extensions.

        Parameters:
        p_file - The image file (a File, a Path, or a character sequence).
        Returns:
        true if the image format is supported, or false otherwise.
      • getImageSize

        public static Size getImageSize​(Object p_file)
                                 throws IOException
        Determine the size of the given image.
        Parameters:
        p_file - The image file (a File, a Path, or a character sequence).
        Returns:
        The size of the given image.
        Throws:
        IOException - If an I/O error occurred, or the image file format is not supported.
      • scaleImage

        public static void scaleImage​(Map<String,​Object> p_params)
                               throws IOException
        Scale an image.

        Valid parameters:

        • inputFile (required) - The input file as a File, a Path, or as a character sequence.
        • outputFile (required) - The output file as a File, a Path, or as a character sequence.
        • format - The format or the scaled image; i.e. 'PNG' (default), 'JPEG', or 'BMP'.
        • width - The new width of the image.
        • height - The new height of the image.
        • maxWidth - The maximum width of the new image. The image will be scaled up to this value but not greater, while the aspect ratio will be maintained.
        • maxHeight - The maximum height of the new image. The image will be scaled up to this value but not greater, while the aspect ratio will be maintained.
        • scaleX - The horizontal scaling factor to be applied.
        • scaleY - The vertical scaling factor to be applied.
        • shrinkOnly - Scale only if the resulting image is smaller than the original. This option can only be used together with maxWidth or maxHeight.
        • rotate - Rotates the image with respect to the image orientation store in the image header.
        • crop - Crop the image. This option can only be used together with maxWidth or width and maxHeight or height.
        Note: width, maxWidth, and scaleX are mutually exclusive; height, maxHeight, and scaleY are mutually exclusive.

        Parameters:
        p_params - The named parameters.
        Throws:
        IOException - If an I/O error occurred, or the image file format is not supported.
      • scaleImageAbs

        public static void scaleImageAbs​(Object p_fileIn,
                                         Object p_fileOut,
                                         Number p_numWidth,
                                         Number p_numHeight,
                                         IMAGE_FORMAT p_imgFormat)
                                  throws IOException
        Scale the given image to the given width and height.
        Parameters:
        p_fileIn - The input file (a File, a Path, or a character sequence).
        p_fileOut - The output file (a File, a Path, or a character sequence).
        p_numWidth - The new width.
        p_numHeight - The new height.
        p_imgFormat - The image format.
        Throws:
        IOException - If an I/O error occurred.
      • scaleImageAbs

        public static void scaleImageAbs​(Object p_fileIn,
                                         Object p_fileOut,
                                         Number p_numWidth,
                                         Number p_numHeight,
                                         String p_strFormat)
                                  throws IOException
        Scale the given image to the given width and height.
        Parameters:
        p_fileIn - The input file (a File, a Path, or a character sequence).
        p_fileOut - The output file (a File, a Path, or a character sequence).
        p_numWidth - The new width.
        p_numHeight - The new height.
        p_strFormat - The format or the scaled image; i.e. 'PNG' (default), 'JPEG', or 'BMP'.
        Throws:
        IOException - If an I/O error occurred.
      • scaleImageRel

        public static void scaleImageRel​(Object p_fileIn,
                                         Object p_fileOut,
                                         Number p_numScaleX,
                                         Number p_numScaleY,
                                         IMAGE_FORMAT p_imgFormat)
                                  throws IOException
        Scale the given image by the specified horizontal and vertical factor.
        Parameters:
        p_fileIn - The input file (a File, a Path, or a character sequence).
        p_fileOut - The output file (a File, a Path, or a character sequence).
        p_numScaleX - The horizontal scaling factor.
        p_numScaleY - The vertical scaling factor.
        p_imgFormat - The image format.
        Throws:
        IOException - If an I/O error occurred.
      • scaleImageRel

        public static void scaleImageRel​(Object p_fileIn,
                                         Object p_fileOut,
                                         Number p_numScaleX,
                                         Number p_numScaleY,
                                         String p_strFormat)
                                  throws IOException
        Scale the given image by the specified horizontal and vertical factor.
        Parameters:
        p_fileIn - The input file (a File, a Path, or a character sequence).
        p_fileOut - The output file (a File, a Path, or a character sequence).
        p_numScaleX - The horizontal scaling factor.
        p_numScaleY - The vertical scaling factor.
        p_strFormat - The format or the scaled image; i.e. 'PNG' (default), 'JPEG', or 'BMP'.
        Throws:
        IOException - If an I/O error occurred.