Table of Contents
Add dependency to build.gradle
.
implementation("com.github.ngoanh2n:image-comparator:1.5.0")
Add dependency to pom.xml
.
<dependency>
<groupId>com.github.ngoanh2n</groupId>
<artifactId>image-comparator</artifactId>
<version>1.5.0</version>
</dependency>
- Compare 2 images
ImageComparisonOptions options = ImageComparisonOptions .builder() .allowedDeviation(0.05) // Default to 0.0 .diffColor(Color.CYAN) // Default to Color.RED .build(); ImageComparisonResult result = ImageComparator.compare(expectedImage, actualImage, options);
- Compare 2 image directories
Path expectedImageDir = Paths.get("data/expected"); Path actualImageDir = Paths.get("data/actual"); ImageComparisonOptions options = ImageComparisonOptions .builder() .allowedDeviation(0.05) // Default to 0.0 .diffColor(Color.CYAN) // Default to Color.RED .build(); ImageBulkComparisonResult result = ImageComparator.compare(expectedImageDir, actualImageDir, options);
ImageComparisonResult
is the result of ImageComparator.compare(expectedImage, actualImage, options)
.
boolean isDifferent = ImageComparisonResult.isDifferent();
int diffSize = ImageComparisonResult.getDiffSize();
BufferedImage diffImage = ImageComparisonResult.getDiffImage();
double allowedDeviation = ImageComparisonResult.getAllowedDeviation();
double currentDeviation = ImageComparisonResult.getCurrentDeviation();
ImageBulkComparisonResult
is the result of ImageComparator.compare(expectedImageDir, actualImageDir, options)
.
boolean hasDiff = ImageBulkComparisonResult.hasDiff();
int diffTotal = ImageBulkComparisonResult.getDiffTotal();
List<ImageComparisonResult> diffResults = ImageBulkComparisonResult.getDiffResults();
ImageComparisonVisitor
for walking through ImageComparator
.
ImageComparisonVisitor.comparisonStarted(ImageComparisonOptions, BufferedImage, BufferedImage)
ImageComparisonVisitor.comparisonFinished(ImageComparisonOptions, BufferedImage, BufferedImage, ImageComparisonResult)
ImageComparisonOutput
for writing comparison output files to specified location.
An implementation of ImageComparisonVisitor
.
- The output is always created at
build/ngoanh2n/img/{yyyyMMdd.HHmmss.SSS}
by default - Use
ImageComparisonResultOptions
to adjust the output behaviors. And set toImageComparisonOptions
ImageComparisonResultOptions resultOptions = ImageComparisonResultOptions .builder() .writeOutputs(false) // Default to true //.location(Paths.get("build/custom")) // Default to build/ngoanh2n/img .build(); ImageComparisonOptions options = ImageComparisonOptions .builder() .resultOptions(resultOptions) // Default to ImageComparisonResultOptions.defaults() .build();
When using Allure as a report framework, should use
com.github.ngoanh2n:image-comparator-allure.
image-comparator-allure
README.