public class ImageProcessor extends Object
| Constructor and Description |
|---|
ImageProcessor(File sourceFile,
File targetFile)
Creates a new
ImageProcessor |
ImageProcessor(File sourceFile,
File targetFile,
boolean checkMagicBytes)
Creates a new
ImageProcessor |
ImageProcessor(File imageMagickPath,
File sourceFile,
File targetFile)
Creates a new
ImageProcessor |
ImageProcessor(File imageMagickPath,
File sourceFile,
File targetFile,
boolean checkMagicBytes)
Creates a new
ImageProcessor |
| Modifier and Type | Method and Description |
|---|---|
ImageProcessor |
autoCrop(int croppingWidth,
int croppingHeight,
int originalWidth,
int originalHeight)
Automatically crops the original image to the required size.
|
ImageProcessor |
autoCrop(int croppingWidth,
int croppingHeight,
int originalWidth,
int originalHeight,
int croppingOffsetX,
int croppingOffsetY)
Automatically crops the original image to the required size.
|
ImageProcessor |
crop(int targetWidth,
int targetHeight,
int offsetWidth,
int offsetHeight)
Adds a crop-option to the
convert-command.
|
ImageProcessor |
fitToHeight(Integer maxHeight)
Fits the image to the given maximum height using
resize(int, int). |
ImageProcessor |
fitToWidth(Integer maxWidth)
Fits the image to the given maximum width using
resize(int, int). |
ImageProcessor |
fitToWidthAndHeight(int maxwidth,
int maxHeight)
Fits the image to the given maximum width and height using
resize(int, int). |
File |
getImage()
Executes the convert-command with all the previously applied options and returns the target-file this
ImageProcessor was created with. |
ImageMetaData |
getMetaData()
Retrieves the
ImageMetaData for the source-file. |
org.im4java.core.IMOperation |
getOp() |
static boolean |
isImageMagickPresent(File imageMagickPath)
Checks whether the ImageMagick convert-command is available.
|
ImageProcessor |
quality(double quality)
Adds a quality-option to the
convert-command.
|
ImageProcessor |
resize(int targetWidth,
int targetHeight)
Adds a resize-option to the
convert-command.
|
ImageProcessor |
resize(int targetWidth,
int targetHeight,
boolean scaleUp)
Adds a resize-option to the
convert-command.
|
ImageProcessor |
rotate(int degrees)
Adds a rotate-option to the
convert-command.
|
static void |
setGlobalSearchPath(File imageMagickPath)
Sets the global search path to the convert-command
|
ImageProcessor |
strip()
Adds a strip-option to the
convert-command.
|
public ImageProcessor(File imageMagickPath, File sourceFile, File targetFile)
ImageProcessorimageMagickPath - the path to the convert-command, if null the system path is being usedsourceFile - the source filetargetFile - the target filepublic ImageProcessor(File imageMagickPath, File sourceFile, File targetFile, boolean checkMagicBytes) throws IOException
ImageProcessorimageMagickPath - the path to the convert-command, if null the system path is being usedsourceFile - the source filetargetFile - the target filecheckMagicBytes - whether or not it should be checked that the source file's extension matches it's content
type, using magic byte detectionIOException - if checkMagicBytes is true and the source file's extension does not match
it's content type determined by magic byte detectionpublic ImageProcessor(File sourceFile, File targetFile)
ImageProcessorsourceFile - the source filetargetFile - the target filepublic ImageProcessor(File sourceFile, File targetFile, boolean checkMagicBytes) throws IOException
ImageProcessorsourceFile - the source filetargetFile - the target filecheckMagicBytes - whether or not it should be checked that the source file's extension matches it's content
type, using magic byte detectionIOException - if checkMagicBytes is true and the source file's extension does not match
it's content type determined by magic byte detectionpublic static boolean isImageMagickPresent(File imageMagickPath)
imageMagickPath - the path to the convert-command, if null the system path is being usedtrue if the convert-command is available, false otherwisesetGlobalSearchPath(File)public static void setGlobalSearchPath(File imageMagickPath)
imageMagickPath - the path to the convert-command, may not be nullpublic ImageMetaData getMetaData() throws IOException
ImageMetaData for the source-file.ImageMetaDataIOException - if the source-file could not be readpublic ImageProcessor rotate(int degrees)
degrees - the degreesImageProcessorpublic ImageProcessor resize(int targetWidth, int targetHeight, boolean scaleUp)
targetWidth - the target width, must be greater 0targetHeight - the target height, must be greater 0scaleUp - set to true if the image should be scaled up (in case its dimensions are smaller than
the desired ones).ImageProcessorresize(int, int)public ImageProcessor resize(int targetWidth, int targetHeight)
targetWidth - the target width, must be greater 0targetHeight - the target height, must be greater 0ImageProcessorpublic ImageProcessor quality(double quality)
quality - the qualityImageProcessorpublic ImageProcessor strip()
ImageProcessorpublic ImageProcessor autoCrop(int croppingWidth, int croppingHeight, int originalWidth, int originalHeight)
croppingWidth - The target width of the image section.croppingHeight - The target height of the image section.originalWidth - The original width of the image.originalHeight - The original height of the image.ImageProcessorautoCrop(int, int, int, int, int, int)public ImageProcessor autoCrop(int croppingWidth, int croppingHeight, int originalWidth, int originalHeight, int croppingOffsetX, int croppingOffsetY)
Automatically crops the original image to the required size.
This is done in two steps. First, a section with the desired aspect ratio is being cropped from the original image. Second, this image section is resized to the desired size.
Example: autoCrop(50, 50, 100, 200, 0, 0) will first crop a squared section from 0,50 to 100,150 and the
resize this section to 50x50.
0,0 _________ 100,0
| |
| |
| |
| |
0,50 |_________|100,50
| |
| cropped |
| |
| section |
|_________|
0,150| |100,150
| |
| |
| |
|_________|
0,200 100,200
Note that the original aspect ratio of the original image might get lost.
croppingWidth - The target width of the image section.croppingHeight - The target height of the image section.originalWidth - The original width of the image.originalHeight - The original height of the image.croppingOffsetX - The X offset for the image section based on the original image.croppingOffsetY - The Y offset for the image section based on the original image.ImageProcessorcrop(int, int, int, int),
resize(int, int)public ImageProcessor crop(int targetWidth, int targetHeight, int offsetWidth, int offsetHeight)
targetWidth - the width of the cuttingtargetHeight - the height of the cuttingoffsetWidth - the width-offset to start cropping at.offsetHeight - the height-offset to start cropping at.ImageProcessorpublic File getImage() throws IOException
ImageProcessor was created with.ImageProcessor was created withIOException - if something goes wrong while executing the convert-commandpublic ImageProcessor fitToWidthAndHeight(int maxwidth, int maxHeight) throws IOException
resize(int, int). No upscaling is done here,
the aspect ratio is being kept.maxwidth - the maximum width of the imagemaxHeight - the maximum height of the imageImageProcessorIOException - if no ImageMetaData could be obtained from the source fileresize(int, int)public ImageProcessor fitToWidth(Integer maxWidth) throws IOException
resize(int, int). No upscaling is done here, the aspect
ratio is being kept.maxWidth - the maximum width of the imageImageProcessorIOException - if no ImageMetaData could be obtained from the source fileresize(int, int)public ImageProcessor fitToHeight(Integer maxHeight) throws IOException
resize(int, int). No upscaling is done here, the aspect
ratio is being kept.maxHeight - the maximum height of the imageImageProcessorIOException - if no ImageMetaData could be obtained from the source fileresize(int, int)public org.im4java.core.IMOperation getOp()
Copyright © 2011–2023 aiticon GmbH. All rights reserved.