source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java@ 16815

Last change on this file since 16815 was 16815, checked in by simon04, 4 years ago

RenderingCLI: handle NoSuchFileException

File size: 25.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Dimension;
7import java.awt.image.BufferedImage;
8import java.io.File;
9import java.io.FileNotFoundException;
10import java.io.IOException;
11import java.nio.file.Files;
12import java.nio.file.NoSuchFileException;
13import java.nio.file.Paths;
14import java.util.ArrayList;
15import java.util.Arrays;
16import java.util.List;
17import java.util.Locale;
18import java.util.Optional;
19import java.util.function.DoubleSupplier;
20import java.util.logging.Level;
21
22import javax.imageio.ImageIO;
23
24import org.openstreetmap.gui.jmapviewer.OsmMercator;
25import org.openstreetmap.josm.cli.CLIModule;
26import org.openstreetmap.josm.data.Bounds;
27import org.openstreetmap.josm.data.ProjectionBounds;
28import org.openstreetmap.josm.data.coor.EastNorth;
29import org.openstreetmap.josm.data.coor.LatLon;
30import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
31import org.openstreetmap.josm.data.osm.DataSet;
32import org.openstreetmap.josm.data.preferences.JosmBaseDirectories;
33import org.openstreetmap.josm.data.preferences.JosmUrls;
34import org.openstreetmap.josm.data.projection.Projection;
35import org.openstreetmap.josm.data.projection.ProjectionRegistry;
36import org.openstreetmap.josm.data.projection.Projections;
37import org.openstreetmap.josm.gui.mappaint.RenderingHelper.StyleData;
38import org.openstreetmap.josm.io.IllegalDataException;
39import org.openstreetmap.josm.io.OsmReader;
40import org.openstreetmap.josm.spi.preferences.Config;
41import org.openstreetmap.josm.spi.preferences.MemoryPreferences;
42import org.openstreetmap.josm.tools.Http1Client;
43import org.openstreetmap.josm.tools.HttpClient;
44import org.openstreetmap.josm.tools.JosmDecimalFormatSymbolsProvider;
45import org.openstreetmap.josm.tools.Logging;
46import org.openstreetmap.josm.tools.OptionParser;
47import org.openstreetmap.josm.tools.OptionParser.OptionCount;
48import org.openstreetmap.josm.tools.OptionParser.OptionParseException;
49import org.openstreetmap.josm.tools.Territories;
50
51/**
52 * Command line interface for rendering osm data to an image file.
53 *
54 * @since 12906
55 */
56public class RenderingCLI implements CLIModule {
57
58 /**
59 * The singleton instance of this class.
60 */
61 public static final RenderingCLI INSTANCE = new RenderingCLI();
62
63 private static final double PIXEL_PER_METER = 96 / 2.54 * 100; // standard value of 96 dpi display resolution
64 private static final int DEFAULT_MAX_IMAGE_SIZE = 20000;
65
66 private boolean argDebug;
67 private boolean argTrace;
68 private String argInput;
69 private String argOutput;
70 private List<StyleData> argStyles;
71 private Integer argZoom;
72 private Double argScale;
73 private Bounds argBounds;
74 private LatLon argAnchor;
75 private Double argWidthM;
76 private Double argHeightM;
77 private Integer argWidthPx;
78 private Integer argHeightPx;
79 private String argProjection;
80 private Integer argMaxImageSize;
81
82 private StyleData argCurrentStyle;
83
84 private enum Option {
85 HELP(false, 'h'),
86 DEBUG(false, '*'),
87 TRACE(false, '*'),
88 INPUT(true, 'i'),
89 STYLE(true, 's'),
90 SETTING(true, '*'),
91 OUTPUT(true, 'o'),
92 ZOOM(true, 'z'),
93 SCALE(true, '*'),
94 BOUNDS(true, 'b'),
95 ANCHOR(true, '*'),
96 WIDTH_M(true, '*'),
97 HEIGHT_M(true, '*'),
98 WIDTH_PX(true, '*'),
99 HEIGHT_PX(true, '*'),
100 PROJECTION(true, '*'),
101 MAX_IMAGE_SIZE(true, '*');
102
103 private final String name;
104 private final boolean requiresArg;
105 private final char shortOption;
106
107 Option(boolean requiresArgument, char shortOption) {
108 this.name = name().toLowerCase(Locale.US).replace('_', '-');
109 this.requiresArg = requiresArgument;
110 this.shortOption = shortOption;
111 }
112
113 /**
114 * Replies the option name
115 * @return The option name, in lowercase
116 */
117 public String getName() {
118 return name;
119 }
120
121 /**
122 * Determines if this option requires an argument.
123 * @return {@code true} if this option requires an argument, {@code false} otherwise
124 */
125 public boolean requiresArgument() {
126 return requiresArg;
127 }
128
129 /**
130 * Replies the short option (single letter) associated with this option.
131 * @return the short option or '*' if there is no short option
132 */
133 public char getShortOption() {
134 return shortOption;
135 }
136 }
137
138 /**
139 * Data class to hold return values for {@link #determineRenderingArea(DataSet)}.
140 *
141 * Package private access for unit tests.
142 */
143 static class RenderingArea {
144 public Bounds bounds;
145 public double scale; // in east-north units per pixel (unlike the --scale option, which is in meter per meter)
146 }
147
148 RenderingCLI() {
149 // hide constructor (package private access for unit tests)
150 }
151
152 @Override
153 public String getActionKeyword() {
154 return "render";
155 }
156
157 @Override
158 public void processArguments(String[] argArray) {
159 try {
160 parseArguments(argArray);
161 initialize();
162 DataSet ds = loadDataset();
163 RenderingArea area = determineRenderingArea(ds);
164 RenderingHelper rh = new RenderingHelper(ds, area.bounds, area.scale, argStyles);
165 checkPreconditions(rh);
166 BufferedImage image = rh.render();
167 writeImageToFile(image);
168 } catch (FileNotFoundException | NoSuchFileException e) {
169 if (Logging.isDebugEnabled()) {
170 e.printStackTrace();
171 }
172 System.err.println(tr("Error - file not found: ''{0}''", e.getMessage()));
173 System.exit(1);
174 } catch (IllegalArgumentException | IllegalDataException | IOException e) {
175 if (Logging.isDebugEnabled()) {
176 e.printStackTrace();
177 }
178 if (e.getMessage() != null) {
179 System.err.println(tr("Error: {0}", e.getMessage()));
180 }
181 System.exit(1);
182 }
183 System.exit(0);
184 }
185
186 /**
187 * Parse command line arguments and do some low-level error checking.
188 * @param argArray the arguments array
189 */
190 void parseArguments(String[] argArray) {
191 Logging.setLogLevel(Level.INFO);
192
193 OptionParser parser = new OptionParser("JOSM rendering");
194 for (Option o : Option.values()) {
195 if (o.requiresArgument()) {
196 parser.addArgumentParameter(o.getName(),
197 o == Option.SETTING ? OptionCount.MULTIPLE : OptionCount.OPTIONAL,
198 arg -> handleOption(o, arg));
199 } else {
200 parser.addFlagParameter(o.getName(), () -> handleOption(o));
201 }
202 if (o.getShortOption() != '*') {
203 parser.addShortAlias(o.getName(), Character.toString(o.getShortOption()));
204 }
205 }
206
207 argCurrentStyle = new StyleData();
208 argStyles = new ArrayList<>();
209
210 parser.parseOptionsOrExit(Arrays.asList(argArray));
211
212 if (argCurrentStyle.styleUrl != null) {
213 argStyles.add(argCurrentStyle);
214 }
215 }
216
217 private void handleOption(Option o) {
218 switch (o) {
219 case HELP:
220 showHelp();
221 System.exit(0);
222 break;
223 case DEBUG:
224 argDebug = true;
225 break;
226 case TRACE:
227 argTrace = true;
228 break;
229 default:
230 throw new AssertionError("Unexpected option index: " + o);
231 }
232 }
233
234 private void handleOption(Option o, String arg) {
235 switch (o) {
236 case INPUT:
237 argInput = arg;
238 break;
239 case STYLE:
240 if (argCurrentStyle.styleUrl != null) {
241 argStyles.add(argCurrentStyle);
242 argCurrentStyle = new StyleData();
243 }
244 argCurrentStyle.styleUrl = arg;
245 break;
246 case OUTPUT:
247 argOutput = arg;
248 break;
249 case ZOOM:
250 try {
251 argZoom = Integer.valueOf(arg);
252 } catch (NumberFormatException nfe) {
253 throw new OptionParseException(
254 tr("Expected integer number for option {0}, but got ''{1}''", "--zoom", arg), nfe);
255 }
256 if (argZoom < 0) {
257 throw new OptionParseException(
258 tr("Expected integer number >= 0 for option {0}, but got ''{1}''", "--zoom", arg));
259 }
260 break;
261 case BOUNDS:
262 if (!"auto".equals(arg)) {
263 try {
264 argBounds = new Bounds(arg, ",", Bounds.ParseMethod.LEFT_BOTTOM_RIGHT_TOP, false);
265 } catch (IllegalArgumentException iae) { // NOPMD
266 throw new OptionParseException(
267 tr("Unable to parse {0} parameter: {1}", "--bounds", iae.getMessage()), iae);
268 }
269 }
270 break;
271
272 case SETTING:
273 String keyval = arg;
274 String[] comp = keyval.split(":", 2);
275 if (comp.length != 2) {
276 throw new OptionParseException(
277 tr("Expected key and value, separated by '':'' character for option {0}, but got ''{1}''",
278 "--setting", arg));
279 }
280 argCurrentStyle.settings.put(comp[0].trim(), comp[1].trim());
281 break;
282 case SCALE:
283 try {
284 argScale = JosmDecimalFormatSymbolsProvider.parseDouble(arg);
285 } catch (NumberFormatException nfe) {
286 throw new OptionParseException(
287 tr("Expected floating point number for option {0}, but got ''{1}''", "--scale", arg), nfe);
288 }
289 break;
290 case ANCHOR:
291 String[] parts = arg.split(",", -1);
292 if (parts.length != 2)
293 throw new OptionParseException(
294 tr("Expected two coordinates, separated by comma, for option {0}, but got ''{1}''", "--anchor",
295 arg));
296 try {
297 double lon = LatLonParser.parseCoordinate(parts[0]);
298 double lat = LatLonParser.parseCoordinate(parts[1]);
299 argAnchor = new LatLon(lat, lon);
300 } catch (IllegalArgumentException iae) { // NOPMD
301 throw new OptionParseException(tr("In option {0}: {1}", "--anchor", iae.getMessage()), iae);
302 }
303 break;
304 case WIDTH_M:
305 try {
306 argWidthM = JosmDecimalFormatSymbolsProvider.parseDouble(arg);
307 } catch (NumberFormatException nfe) {
308 throw new OptionParseException(
309 tr("Expected floating point number for option {0}, but got ''{1}''", "--width-m", arg), nfe);
310 }
311 if (argWidthM <= 0)
312 throw new OptionParseException(
313 tr("Expected floating point number > 0 for option {0}, but got ''{1}''", "--width-m", arg));
314 break;
315 case HEIGHT_M:
316 try {
317 argHeightM = JosmDecimalFormatSymbolsProvider.parseDouble(arg);
318 } catch (NumberFormatException nfe) {
319 throw new OptionParseException(
320 tr("Expected floating point number for option {0}, but got ''{1}''", "--height-m", arg), nfe);
321 }
322 if (argHeightM <= 0)
323 throw new OptionParseException(
324 tr("Expected floating point number > 0 for option {0}, but got ''{1}''", "--width-m", arg));
325 break;
326 case WIDTH_PX:
327 try {
328 argWidthPx = Integer.valueOf(arg);
329 } catch (NumberFormatException nfe) {
330 throw new OptionParseException(
331 tr("Expected integer number for option {0}, but got ''{1}''", "--width-px", arg), nfe);
332 }
333 if (argWidthPx <= 0)
334 throw new OptionParseException(
335 tr("Expected integer number > 0 for option {0}, but got ''{1}''", "--width-px", arg));
336 break;
337 case HEIGHT_PX:
338 try {
339 argHeightPx = Integer.valueOf(arg);
340 } catch (NumberFormatException nfe) {
341 throw new OptionParseException(
342 tr("Expected integer number for option {0}, but got ''{1}''", "--height-px", arg), nfe);
343 }
344 if (argHeightPx <= 0) {
345 throw new OptionParseException(
346 tr("Expected integer number > 0 for option {0}, but got ''{1}''", "--height-px", arg));
347 }
348 break;
349 case PROJECTION:
350 argProjection = arg;
351 break;
352 case MAX_IMAGE_SIZE:
353 try {
354 argMaxImageSize = Integer.valueOf(arg);
355 } catch (NumberFormatException nfe) {
356 throw new OptionParseException(
357 tr("Expected integer number for option {0}, but got ''{1}''", "--max-image-size", arg), nfe);
358 }
359 if (argMaxImageSize < 0) {
360 throw new OptionParseException(
361 tr("Expected integer number >= 0 for option {0}, but got ''{1}''", "--max-image-size", arg));
362 }
363 break;
364 default:
365 throw new AssertionError("Unexpected option index: " + o);
366 }
367 }
368
369 /**
370 * Displays help on the console
371 */
372 public static void showHelp() {
373 System.out.println(getHelp());
374 }
375
376 private static String getHelp() {
377 return tr("JOSM rendering command line interface")+"\n\n"+
378 tr("Usage")+":\n"+
379 "\tjava -jar josm.jar render <options>\n\n"+
380 tr("Description")+":\n"+
381 tr("Renders data and saves the result to an image file.")+"\n\n"+
382 tr("Options")+":\n"+
383 "\t--help|-h "+tr("Show this help")+"\n"+
384 "\t--input|-i <file> "+tr("Input data file name (.osm)")+"\n"+
385 "\t--output|-o <file> "+tr("Output image file name (.png); defaults to ''{0}''", "out.png")+"\n"+
386 "\t--style|-s <file> "+tr("Style file to use for rendering (.mapcss or .zip)")+"\n"+
387 "\t "+tr("This option can be repeated to load multiple styles.")+"\n"+
388 "\t--setting <key>:<value> "+tr("Style setting (in JOSM accessible in the style list dialog right click menu)")+"\n"+
389 "\t "+tr("Applies to the last style loaded with the {0} option.", "--style")+"\n"+
390 "\t--zoom|-z <lvl> "+tr("Select zoom level to render. (integer value, 0=entire earth, 18=street level)")+"\n"+
391 "\t--scale <scale> "+tr("Select the map scale")+"\n"+
392 "\t "+tr("A value of 10000 denotes a scale of 1:10000 (1 cm on the map equals 100 m on the ground; "
393 + "display resolution: 96 dpi)")+"\n"+
394 "\t "+tr("Options {0} and {1} are mutually exclusive.", "--zoom", "--scale")+"\n"+
395 "\t--bounds|-b auto|<min_lon>,<min_lat>,<max_lon>,<max_lat>\n"+
396 "\t "+tr("Area to render, default value is ''{0}''", "auto")+"\n"+
397 "\t "+tr("With keyword ''{0}'', the downloaded area in the .osm input file will be used (if recorded).",
398 "auto")+"\n"+
399 "\t--anchor <lon>,<lat> "+tr("Specify bottom left corner of the rendering area")+"\n"+
400 "\t "+tr("Used in combination with width and height options to determine the area to render.")+"\n"+
401 "\t--width-m <number> "+tr("Width of the rendered area, in meter")+"\n"+
402 "\t--height-m <number> "+tr("Height of the rendered area, in meter")+"\n"+
403 "\t--width-px <number> "+tr("Width of the target image, in pixel")+"\n"+
404 "\t--height-px <number> "+tr("Height of the target image, in pixel")+"\n"+
405 "\t--projection <code> "+tr("Projection to use, default value ''{0}'' (web-Mercator)", "epsg:3857")+"\n"+
406 "\t--max-image-size <number> "+tr("Maximum image width/height in pixel (''{0}'' means no limit), default value: {1}",
407 0, Integer.toString(DEFAULT_MAX_IMAGE_SIZE))+"\n"+
408 "\n"+
409 tr("To specify the rendered area and scale, the options can be combined in various ways")+":\n"+
410 " * --bounds (--zoom|--scale|--width-px|--height-px)\n"+
411 " * --anchor (--width-m|--width-px) (--height-m|--height-px) (--zoom|--scale)\n"+
412 " * --anchor --width-m --height-m (--width-px|--height-px)\n"+
413 " * --anchor --width-px --height-px (--width-m|--height-m)\n"+
414 tr("If neither ''{0}'' nor ''{1}'' is given, the default value {2} takes effect "
415 + "and the bounds of the download area in the .osm input file are used.",
416 "bounds", "anchor", "--bounds=auto")+"\n\n"+
417 tr("Examples")+":\n"+
418 " java -jar josm.jar render -i data.osm -s style.mapcss -z 16\n"+
419 " josm render -i data.osm -s style.mapcss --scale 5000\n"+
420 " josm render -i data.osm -s style.mapcss -z 16 -o image.png\n"+
421 " josm render -i data.osm -s elemstyles.mapcss --setting hide_icons:false -z 16\n"+
422 " josm render -i data.osm -s style.mapcss -s another_style.mapcss -z 16 -o image.png\n"+
423 " josm render -i data.osm -s style.mapcss --bounds 21.151,51.401,21.152,51.402 -z 16\n"+
424 " josm render -i data.osm -s style.mapcss --anchor 21.151,51.401 --width-m 500 --height-m 300 -z 16\n"+
425 " josm render -i data.osm -s style.mapcss --anchor 21.151,51.401 --width-m 500 --height-m 300 --width-px 1800\n"+
426 " josm render -i data.osm -s style.mapcss --scale 5000 --projection epsg:4326\n";
427 }
428
429 /**
430 * Initialization.
431 *
432 * Requires arguments to be parsed already ({@link #parseArguments(java.lang.String[])}).
433 */
434 void initialize() {
435 Logging.setLogLevel(getLogLevel());
436 HttpClient.setFactory(Http1Client::new);
437
438 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); // for right-left-hand traffic cache file
439 Config.setPreferencesInstance(new MemoryPreferences());
440 Config.setUrlsProvider(JosmUrls.getInstance());
441 Config.getPref().putBoolean("mappaint.auto_reload_local_styles", false); // unnecessary to listen for external changes
442 String projCode = Optional.ofNullable(argProjection).orElse("epsg:3857");
443 ProjectionRegistry.setProjection(Projections.getProjectionByCode(projCode.toUpperCase(Locale.US)));
444
445 Territories.initializeInternalData();
446 }
447
448 private Level getLogLevel() {
449 if (argTrace) {
450 return Logging.LEVEL_TRACE;
451 } else if (argDebug) {
452 return Logging.LEVEL_DEBUG;
453 } else {
454 return Logging.LEVEL_INFO;
455 }
456 }
457
458 /**
459 * Find the area to render and the scale, given certain command line options and the dataset.
460 * @param ds the dataset
461 * @return area to render and the scale
462 */
463 RenderingArea determineRenderingArea(DataSet ds) {
464
465 Projection proj = ProjectionRegistry.getProjection();
466 Double scale = null; // scale in east-north units per pixel
467 if (argZoom != null) {
468 scale = OsmMercator.EARTH_RADIUS * Math.PI * 2 / Math.pow(2, argZoom) / OsmMercator.DEFAUL_TILE_SIZE
469 / proj.getMetersPerUnit();
470 }
471 Bounds bounds = argBounds;
472 ProjectionBounds pb = null;
473
474 if (bounds == null) {
475 if (argAnchor != null) {
476 EastNorth projAnchor = proj.latlon2eastNorth(argAnchor);
477
478 double enPerMeter = Double.NaN;
479 DoubleSupplier getEnPerMeter = () -> {
480 double shiftMeter = 10;
481 EastNorth projAnchorShifted = projAnchor.add(shiftMeter / proj.getMetersPerUnit(),
482 shiftMeter / proj.getMetersPerUnit());
483 LatLon anchorShifted = proj.eastNorth2latlon(projAnchorShifted);
484 return projAnchor.distance(projAnchorShifted) / argAnchor.greatCircleDistance(anchorShifted);
485 };
486
487 if (scale == null) {
488 if (argScale != null) {
489 enPerMeter = getEnPerMeter.getAsDouble();
490 scale = argScale * enPerMeter / PIXEL_PER_METER;
491 } else if (argWidthM != null && argWidthPx != null) {
492 enPerMeter = getEnPerMeter.getAsDouble();
493 scale = argWidthM / argWidthPx * enPerMeter;
494 } else if (argHeightM != null && argHeightPx != null) {
495 enPerMeter = getEnPerMeter.getAsDouble();
496 scale = argHeightM / argHeightPx * enPerMeter;
497 } else {
498 throw new IllegalArgumentException(
499 tr("Argument {0} given, but scale cannot be determined from remaining arguments",
500 "--anchor"));
501 }
502 }
503
504 double widthEn;
505 if (argWidthM != null) {
506 if (Double.isNaN(enPerMeter)) {
507 enPerMeter = getEnPerMeter.getAsDouble();
508 }
509 widthEn = argWidthM * enPerMeter;
510 } else if (argWidthPx != null) {
511 widthEn = argWidthPx * scale;
512 } else {
513 throw new IllegalArgumentException(
514 tr("Argument {0} given, expected {1} or {2}", "--anchor", "--width-m", "--width-px"));
515 }
516
517 double heightEn;
518 if (argHeightM != null) {
519 if (Double.isNaN(enPerMeter)) {
520 enPerMeter = getEnPerMeter.getAsDouble();
521 }
522 heightEn = argHeightM * enPerMeter;
523 } else if (argHeightPx != null) {
524 heightEn = argHeightPx * scale;
525 } else {
526 throw new IllegalArgumentException(
527 tr("Argument {0} given, expected {1} or {2}", "--anchor", "--height-m", "--height-px"));
528 }
529 pb = new ProjectionBounds(projAnchor);
530 pb.extend(new EastNorth(projAnchor.east() + widthEn, projAnchor.north() + heightEn));
531 bounds = new Bounds(proj.eastNorth2latlon(pb.getMin()), false);
532 bounds.extend(proj.eastNorth2latlon(pb.getMax()));
533 } else {
534 if (ds.getDataSourceBounds().isEmpty()) {
535 throw new IllegalArgumentException(
536 tr("{0} mode, but no bounds found in osm data input file", "--bounds=auto"));
537 }
538 bounds = ds.getDataSourceBounds().get(0);
539 }
540 }
541
542 if (pb == null) {
543 pb = new ProjectionBounds();
544 pb.extend(proj.latlon2eastNorth(bounds.getMin()));
545 pb.extend(proj.latlon2eastNorth(bounds.getMax()));
546 }
547
548 if (scale == null) {
549 if (argScale != null) {
550 double enPerMeter = pb.getMin().distance(pb.getMax())
551 / bounds.getMin().greatCircleDistance(bounds.getMax());
552 scale = argScale * enPerMeter / PIXEL_PER_METER;
553 } else if (argWidthPx != null) {
554 scale = (pb.maxEast - pb.minEast) / argWidthPx;
555 } else if (argHeightPx != null) {
556 scale = (pb.maxNorth - pb.minNorth) / argHeightPx;
557 } else {
558 throw new IllegalArgumentException(
559 tr("Unable to determine scale, one of the options {0}, {1}, {2} or {3} expected", "--zoom",
560 "--scale", "--width-px", "--height-px"));
561 }
562 }
563
564 RenderingArea ra = new RenderingArea();
565 ra.bounds = bounds;
566 ra.scale = scale;
567 return ra;
568 }
569
570 private DataSet loadDataset() throws IOException, IllegalDataException {
571 if (argInput == null) {
572 throw new IllegalArgumentException(tr("Missing argument - input data file ({0})", "--input|-i"));
573 }
574 try {
575 return OsmReader.parseDataSet(Files.newInputStream(Paths.get(argInput)), null);
576 } catch (IllegalDataException e) {
577 throw new IllegalDataException(tr("In .osm data file ''{0}'' - ", argInput) + e.getMessage(), e);
578 }
579 }
580
581 private void checkPreconditions(RenderingHelper rh) {
582 if (argStyles.isEmpty())
583 throw new IllegalArgumentException(tr("Missing argument - at least one style expected ({0})", "--style"));
584
585 Dimension imgSize = rh.getImageSize();
586 Logging.debug("image size (px): {0}x{1}", imgSize.width, imgSize.height);
587 int maxSize = Optional.ofNullable(argMaxImageSize).orElse(DEFAULT_MAX_IMAGE_SIZE);
588 if (maxSize != 0 && (imgSize.width > maxSize || imgSize.height > maxSize)) {
589 throw new IllegalArgumentException(
590 tr("Image dimensions ({0}x{1}) exceeds maximum image size {2} (use option {3} to change limit)",
591 imgSize.width, imgSize.height, maxSize, "--max-image-size"));
592 }
593 }
594
595 private void writeImageToFile(BufferedImage image) throws IOException {
596 String output = Optional.ofNullable(argOutput).orElse("out.png");
597 ImageIO.write(image, "png", new File(output));
598 }
599}
Note: See TracBrowser for help on using the repository browser.