Skip to content

Instantly share code, notes, and snippets.

Werbth Rocha werbth

Block or report user

Report or block werbth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
werbth /
Last active Mar 5, 2018
Given a jpeg image as InputStream, resize it and return another InputStream.
public static InputStream resizeImage(InputStream inputStream, int width, int height) throws IOException {
BufferedImage sourceImage =;
Image thumbnail = sourceImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage bufferedThumbnail = new BufferedImage(thumbnail.getWidth(null),
bufferedThumbnail.getGraphics().drawImage(thumbnail, 0, 0, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedThumbnail, "jpeg", baos);
return new ByteArrayInputStream(baos.toByteArray());
You can’t perform that action at this time.