code: public static byte[] writeImageToBytes(BufferedImage image,
  			String formatName) throws IOException {
  		ByteArrayOutputStream stream = new ByteArrayOutputStream();
  		ImageIO.write(image, formatName, stream);
  		stream.flush();
  		byte[] bytes = stream.toByteArray();
  		stream.close();
  		return bytes;
  	}
docs: Write the image to bytes in the provided format
  
  @param image
  buffered image
  @param formatName
  image format name
  @return image bytes
  @throws IOException
  upon failure
  @since 1.1.2