Class ImageHelper
java.lang.Object
de.uplanet.lucy.server.scripting.groovy.ImageHelper
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
This class represents a collection of image metadata directories.static final class
This class represents an image metadata directory. -
Method Summary
Modifier and TypeMethodDescriptionstatic IMAGE_FORMAT
getImageFormat
(Object p_file) Get the image format of the given file.getImageMetaData
(Object p_file) Get metadata of the given image file.static Size
getImageSize
(Object p_file) Determine the size of the given image.static boolean
isSupportedImageFormat
(Object p_file) Check if the given file has a supported image format.static void
scaleImage
(Map<String, Object> p_params) Scale an image.static void
scaleImageAbs
(Object p_fileIn, Object p_fileOut, Number p_numWidth, Number p_numHeight, IMAGE_FORMAT p_imgFormat) Scale the given image to the given width and height.static void
scaleImageAbs
(Object p_fileIn, Object p_fileOut, Number p_numWidth, Number p_numHeight, String p_strFormat) Scale the given image to the given width and height.static void
scaleImageRel
(Object p_fileIn, Object p_fileOut, Number p_numScaleX, Number p_numScaleY, IMAGE_FORMAT p_imgFormat) Scale the given image by the specified horizontal and vertical factor.static void
scaleImageRel
(Object p_fileIn, Object p_fileOut, Number p_numScaleX, Number p_numScaleY, String p_strFormat) Scale the given image by the specified horizontal and vertical factor.
-
Method Details
-
getImageMetaData
Get metadata of the given image file. -
getImageFormat
Get the image format of the given file.Currently the image format is derived from the file extension.
-
isSupportedImageFormat
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.
-
getImageSize
Determine the size of the given image.- Parameters:
p_file
- The image file (aFile
, aPath
, 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
Scale an image.Valid parameters:
inputFile
(required) - The input file as aFile
, aPath
, or as a character sequence.outputFile
(required) - The output file as aFile
, aPath
, 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 withmaxWidth
ormaxHeight
.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 withmaxWidth
orwidth
andmaxHeight
orheight
.
width
,maxWidth
, andscaleX
are mutually exclusive;height
,maxHeight
, andscaleY
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 (aFile
, aPath
, or a character sequence).p_fileOut
- The output file (aFile
, aPath
, 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 (aFile
, aPath
, or a character sequence).p_fileOut
- The output file (aFile
, aPath
, 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 (aFile
, aPath
, or a character sequence).p_fileOut
- The output file (aFile
, aPath
, 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 (aFile
, aPath
, or a character sequence).p_fileOut
- The output file (aFile
, aPath
, 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.
-