Skip to content

Instantly share code, notes, and snippets.

@farhan-raza
Created February 12, 2025 12:44
Show Gist options
  • Save farhan-raza/8fe4a5dab6401c295df40bfa0c364e0f to your computer and use it in GitHub Desktop.
Save farhan-raza/8fe4a5dab6401c295df40bfa0c364e0f to your computer and use it in GitHub Desktop.
Resize Images in Java | Change Image Size
// Load image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("aspose-logo.png");
// Cache image data
if (!image.isCached())
{
image.cacheData();
}
// Specify width and height
int newWidth = image.getWidth() / 2;
image.resizeWidthProportionally(newWidth);
int newHeight = image.getHeight() / 2;
image.resizeHeightProportionally(newHeight);
// Save image
image.save("ResizeRasterImage.png");
// Load input vector image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.svg");
// Resize image as PNG
image.resize(image.getWidth() * 10,image.getHeight() * 15);
com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions();
options.setVectorRasterizationOptions(new com.aspose.imaging.imageoptions.SvgRasterizationOptions());
// Save output resized image
image.save("resize.png", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment