Package com.applitools.utils
Class ImageUtils
- java.lang.Object
-
- com.applitools.utils.ImageUtils
-
public class ImageUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static intREQUIRED_IMAGE_TYPE
-
Constructor Summary
Constructors Constructor Description ImageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Detail
-
REQUIRED_IMAGE_TYPE
public static final int REQUIRED_IMAGE_TYPE
- See Also:
- Constant Field Values
-
-
Method Detail
-
normalizeImageType
public static BufferedImage normalizeImageType(BufferedImage image)
-
encodeAsPng
public static byte[] encodeAsPng(BufferedImage image)
Encodes a given image as PNG.- Parameters:
image- The image to encode.- Returns:
- The PNG bytes representation of the image.
-
imageFromFile
public static BufferedImage imageFromFile(String path) throws com.applitools.eyes.EyesException
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
public static String base64FromImage(BufferedImage image)
- 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
public static BufferedImage getImagePart(BufferedImage image, com.applitools.eyes.Region region)
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
public static BufferedImage rotateImage(BufferedImage image, double deg)
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
public static boolean areImagesEqual(BufferedImage img1, BufferedImage img2)
-
copyImageWithType
public static BufferedImage copyImageWithType(BufferedImage src, int updatedType)
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
public static BufferedImage scaleImage(BufferedImage image, double scaleRatio)
-
scaleImage
public static BufferedImage scaleImage(BufferedImage image, double scaleRatio, boolean isMobile)
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
public static BufferedImage resizeImage(BufferedImage image, int targetWidth, int targetHeight)
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
public static BufferedImage cropImage(BufferedImage image, com.applitools.eyes.Region regionToCrop)
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
public static void saveImage(BufferedImage image, String filename)
Save image to local file system- Parameters:
image- The image to save.filename- The path to save image
-
imageFromUrl
public static BufferedImage imageFromUrl(URL url)
-
-