Package com.applitools.utils
Class ImageUtils
java.lang.Object
com.applitools.utils.ImageUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanareImagesEqual(BufferedImage img1, BufferedImage img2) static Stringbase64FromImage(BufferedImage image) static BufferedImagecopyImageWithType(BufferedImage src, int updatedType) Creates a copy of an image with an updated image type.static BufferedImagecropImage(com.applitools.eyes.Logger logger, BufferedImage image, Rectangle regionToCrop) static BufferedImagecropImage(BufferedImage image, com.applitools.eyes.Region regionToCrop) Removes a given region from the image.static byte[]encodeAsPng(BufferedImage image) Encodes a given image as PNG.static BufferedImagegetImagePart(BufferedImage image, com.applitools.eyes.Region region) Get a copy of the part of the image given by region.static BufferedImageimageFromBase64(String image64) Creates aBufferedImageinstance from a base64 encoding of an image's bytes.static BufferedImageimageFromBytes(byte[] imageBytes) Creates a BufferedImage instance from raw image bytes.static BufferedImageimageFromFile(String path) Creates aBufferedImagefrom an image file specified bypath.static BufferedImageimageFromResource(String resource) Creates aBufferedImagefrom an image file specified byresource.static BufferedImageimageFromStream(InputStream stream) Creates aBufferedImagefrom an input stream specified bystream.static BufferedImageimageFromUrl(URL url) static BufferedImagenormalizeImageType(BufferedImage image) static BufferedImageresizeImage(BufferedImage image, int targetWidth, int targetHeight) Scales an image by the given ratiostatic BufferedImagerotateImage(BufferedImage image, double deg) Rotates an image by the given degrees.static voidsaveImage(BufferedImage image, String filename) Save image to local file systemstatic BufferedImagescaleImage(BufferedImage image, double scaleRatio) static BufferedImagescaleImage(BufferedImage image, double scaleRatio, boolean isMobile) Scales an image by the given ratio
-
Field Details
-
REQUIRED_IMAGE_TYPE
public static final int REQUIRED_IMAGE_TYPE- See Also:
-
-
Constructor Details
-
ImageUtils
public ImageUtils()
-
-
Method Details
-
normalizeImageType
-
encodeAsPng
Encodes a given image as PNG.- Parameters:
image- The image to encode.- Returns:
- The PNG bytes representation of the image.
-
imageFromFile
Creates aBufferedImagefrom an image file specified bypath.- Parameters:
path- The path to the image file.- Returns:
- A
BufferedImageinstance. - Throws:
com.applitools.eyes.EyesException- If there was a problem creating theBufferedImageinstance.
-
imageFromResource
public static BufferedImage imageFromResource(String resource) throws com.applitools.eyes.EyesException Creates aBufferedImagefrom an image file specified byresource.- Parameters:
resource- The resource path.- Returns:
- A
BufferedImageinstance. - Throws:
com.applitools.eyes.EyesException- If there was a problem creating theBufferedImageinstance.
-
imageFromStream
public static BufferedImage imageFromStream(InputStream stream) throws com.applitools.eyes.EyesException Creates aBufferedImagefrom an input stream specified bystream.- Parameters:
stream- The input stream.- Returns:
- A
BufferedImageinstance. - Throws:
com.applitools.eyes.EyesException- If there was a problem creating theBufferedImageinstance.
-
imageFromBase64
public static BufferedImage imageFromBase64(String image64) throws com.applitools.eyes.EyesException Creates aBufferedImageinstance from a base64 encoding of an image's bytes.- Parameters:
image64- The base64 encoding of an image's bytes.- Returns:
- A
BufferedImageinstance. - Throws:
com.applitools.eyes.EyesException- If there was a problem creating theBufferedImageinstance.
-
base64FromImage
- Parameters:
image- The image from which to get its base64 representation.- Returns:
- The base64 representation of the image (bytes encoded as PNG).
-
imageFromBytes
public static BufferedImage imageFromBytes(byte[] imageBytes) throws com.applitools.eyes.EyesException Creates a BufferedImage instance from raw image bytes.- Parameters:
imageBytes- The raw bytes of the image.- Returns:
- A BufferedImage instance representing the image.
- Throws:
com.applitools.eyes.EyesException- If there was a problem creating theBufferedImageinstance.
-
getImagePart
Get a copy of the part of the image given by region.- Parameters:
image- The image from which to get the part.region- The region which should be copied from the image.- Returns:
- The part of the image.
-
rotateImage
Rotates an image by the given degrees.- Parameters:
image- The image to rotate.deg- The degrees by which to rotate the image.- Returns:
- A rotated image.
-
areImagesEqual
-
copyImageWithType
Creates a copy of an image with an updated image type.- Parameters:
src- The image to copy.updatedType- The type of the copied image. SeeBufferedImage.getType().- Returns:
- A copy of the
srcof the requested type.
-
scaleImage
-
scaleImage
Scales an image by the given ratio- Parameters:
image- The image to scale.scaleRatio- Factor to multiply the image dimensions by- Returns:
- If the scale ratio != 1, returns a new scaled image, otherwise, returns the original image.
-
resizeImage
Scales an image by the given ratio- Parameters:
image- The image to scale.targetWidth- The width to resize the image totargetHeight- The height to resize the image to- Returns:
- If the size of image equal to target size, returns the original image, otherwise, returns a new resized image.
-
cropImage
public static BufferedImage cropImage(com.applitools.eyes.Logger logger, BufferedImage image, Rectangle regionToCrop) -
cropImage
Removes a given region from the image.- Parameters:
image- The image to crop.regionToCrop- The region to crop from the image.- Returns:
- A new image without the cropped region.
-
saveImage
Save image to local file system- Parameters:
image- The image to save.filename- The path to save image
-
imageFromUrl
-