Repository navigation
Core functionalities
Before starting any image processing, ImageProcessing object needs to be created and image should be loaded.
ImageProcessing image = new ImageProcessing();
image.open("/home/user/city.jpg");After image processing is finished, final image can be saved to file.
image.save("/home/user/output.jpg");If you want to save file in different format, than original image, use overloaded save method.
image.save("/home/user/output.png", ImageType.PNG);In order to change image size, use resize method and provide at least one dimension.
If only one dimension is defined, other is calculated automatically, so image aspect ratio won't change.
image.resize(800, null);image.resize(null, 400);If both dimensions are defined, image is resized to exact size, even if it will change image aspect ratio.
image.resize(200, 200);To cut part of the image use crop method. First two parameters define top-left corner. Third and fourth parameters are width and height of cropped area.
image.crop(1400, 420, 120, 180);There are two ways to rotate image. First method allows rotating only by multiplicity of 90 degrees.
image.rotate(Rotation.HALF);Second allows rotating by any amount of degrees, but requires to provide background color to use around rotated image.
image.rotate(20, Color.BLUE);To flip image horizontally or vertically use one of two provided methods: flipHorizontally() and flipVertically().
image.flipHorizontally();To render text on image use drawText method and provide text to render, define its color, font, and placement.
image.drawText("Gdansk", Color.BLACK, new Font("SansSerif", Font.BOLD, 64), 100, 100);To help with text allignment you can use overloaded method, that allows to control horizontal and vertical alignment of rendered text.
Font textFont = new Font("SansSerif", Font.BOLD, 96);
image.drawText("Gdansk", Color.WHITE, textFont, 800, 500, TextHorizontalPosition.CENTER, TextVerticalPosition.MIDDLE);To draw one image on another first you need to load image, but instead of using open() method which would replace image used for processing, use load() method, that will return ImageDrawEntity object with loaded image. After that you can use it in drawImage() method.
ImageDrawEntity coatOfArms = image.load("/home/user/coat-of-arms.png");
image.drawImage(coatOfArms, 480, 20);There are three methods for generating thumbnails, each providing different result.
First one scales down image to fit defined size, but if thumbnail image aspect ratio is different, than original image, it will make it smaller horizontally or vertically.
image.thumbnailScale(200, 200);Second works similar, but if image aspect ratio is different, it fills top/bottom or left/right bars with defined background color at the image edges in order to create thumbnail with exact defined width and height.
image.thumbnailScale(200, 200, Color.YELLOW);Third method will fit image to provided dimensions and cut off any edges outside thumbnail area if original image has different aspect ratio.
image.thumbnailCrop(200, 200);








