+ boolean ok = false;
+ try {
+ ok = ImageIO.write(image, format, target);
+ } catch (IOException e) {
+ ok = false;
+ }
+
+ // Some formats are not reliable
+ // Second change: PNG
+ if (!ok && !format.equals("png")) {
+ ok = ImageIO.write(image, "png", target);
+ }
+
+ if (!ok) {
+ throw new IOException(
+ "Cannot find a writer for this image and format: "
+ + format);