public class ImageMagickHelper extends Object
The ImageMagick needs to be installed independently on the system. This class provides a convenient
way to run it by passing a terminal command. The command can either be specified explicitly or by a mean
of environment variable MAGICK_COMPARE_ENVIRONMENT_VARIABLE.
| Modifier and Type | Field and Description |
|---|---|
static String |
MAGICK_COMPARE_ENVIRONMENT_VARIABLE
The name of the environment variable with the command to execute ImageMagic comparison operations.
|
| Constructor and Description |
|---|
ImageMagickHelper()
Creates new instance that will rely on ImageMagick execution command defined by
MAGICK_COMPARE_ENVIRONMENT_VARIABLE environment variable. |
ImageMagickHelper(String newCompareExec)
Creates new instance that will rely on ImageMagick execution command defined as passed argument.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getCliExecutionCommand()
Returns a command that is used to run the utility.
|
boolean |
runImageMagickImageCompare(String outImageFilePath,
String cmpImageFilePath,
String diffImageName)
Runs imageMagick to visually compare images and generate difference output.
|
boolean |
runImageMagickImageCompare(String outImageFilePath,
String cmpImageFilePath,
String diffImageName,
String fuzzValue)
Runs imageMagick to visually compare images with the specified fuzziness value and generate difference output.
|
ImageMagickCompareResult |
runImageMagickImageCompareAndGetResult(String outImageFilePath,
String cmpImageFilePath,
String diffImageName,
String fuzzValue)
Runs imageMagick to visually compare images with the specified fuzziness value and generate difference output.
|
boolean |
runImageMagickImageCompareWithThreshold(String outImageFilePath,
String cmpImageFilePath,
String diffImageName,
String fuzzValue,
long threshold)
Runs imageMagick to visually compare images with the specified fuzziness value and given threshold
and generate difference output.
|
public static final String MAGICK_COMPARE_ENVIRONMENT_VARIABLE
public ImageMagickHelper()
MAGICK_COMPARE_ENVIRONMENT_VARIABLE environment variable.public ImageMagickHelper(String newCompareExec)
newCompareExec - the ImageMagick execution command; if null - environment variables will be used insteadpublic String getCliExecutionCommand()
public boolean runImageMagickImageCompare(String outImageFilePath, String cmpImageFilePath, String diffImageName) throws IOException, InterruptedException
Note, that this method may create temporary files.
outImageFilePath - Path to the output image filecmpImageFilePath - Path to the cmp image filediffImageName - Path to the difference output image fileIOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing ImageMagick.public boolean runImageMagickImageCompare(String outImageFilePath, String cmpImageFilePath, String diffImageName, String fuzzValue) throws IOException, InterruptedException
Note, that this method may create temporary files.
outImageFilePath - Path to the output image filecmpImageFilePath - Path to the cmp image filediffImageName - Path to the difference output image filefuzzValue - String fuzziness value to compare images. Should be formatted as string with integer
or decimal number. Can be null, if it is not required to use fuzzinessIOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing ImageMagick.public boolean runImageMagickImageCompareWithThreshold(String outImageFilePath, String cmpImageFilePath, String diffImageName, String fuzzValue, long threshold) throws IOException, InterruptedException
Note, that this method may create temporary files.
outImageFilePath - Path to the output image filecmpImageFilePath - Path to the cmp image filediffImageName - Path to the difference output image filefuzzValue - String fuzziness value to compare images. Should be formatted as string with integer
or decimal number. Can be null, if it is not required to use fuzzinessthreshold - Long value of accepted threshold.IOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing ImageMagick.public ImageMagickCompareResult runImageMagickImageCompareAndGetResult(String outImageFilePath, String cmpImageFilePath, String diffImageName, String fuzzValue) throws IOException, InterruptedException
ImageMagickCompareResult, containing comparing result information,
such as boolean result value and the number of different pixels.
Note, that this method may create temporary files.
outImageFilePath - Path to the output image filecmpImageFilePath - Path to the cmp image filediffImageName - Path to the difference output image filefuzzValue - String fuzziness value to compare images. Should be formatted as string with integer
or decimal number. Can be null, if it is not required to use fuzzinessImageMagickCompareResult. containing comparing result information.IOException - if there are file's reading/writing issuesInterruptedException - if there is thread interruption while executing ImageMagick.Copyright © 1998–2025 Apryse Group NV. All rights reserved.