@@ -151,7 +151,17 @@ private int openPreview(CommandContext<CommandSourceStack> context) throws Comma
151151 if (GuiHelpers .getCurrentGui (source .getPlayer ()) instanceof PreviewGui previewGui ) {
152152 previewGui .close ();
153153 }
154- new PreviewGui (context .getSource ().getPlayer (), image , input , DitherMode .NONE , image .getWidth (), image .getHeight ());
154+
155+ var width = image .getWidth ();
156+ var height = image .getHeight ();
157+
158+ if (height > CONFIG .maxSize || width > CONFIG .maxSize ) {
159+ var scaleDown = Math .min (CONFIG .maxSize / (double ) height , CONFIG .maxSize / (double ) width );
160+ width = (int ) (width * scaleDown );
161+ height = (int ) (height * scaleDown );
162+ }
163+
164+ new PreviewGui (context .getSource ().getPlayer (), image , input , DitherMode .NONE , width , height );
155165
156166 return null ;
157167 }, source .getServer ());
@@ -299,18 +309,27 @@ private int createMap(CommandContext<CommandSourceStack> context) throws Command
299309 try {
300310 width = IntegerArgumentType .getInteger (context , "width" );
301311 height = IntegerArgumentType .getInteger (context , "height" );
312+
313+ if (height > CONFIG .maxSize || width > CONFIG .maxSize ) {
314+ int finalHeight = height ;
315+ int finalWidth = width ;
316+ source .sendSuccess (() -> Component .literal ("Map size exceeds maximum allowed (" + CONFIG .maxSize + "x" + CONFIG .maxSize + "), was " + finalWidth + "x" + finalHeight ), false );
317+ return null ;
318+ }
302319 } catch (Throwable e ) {
303320 width = image .getWidth ();
304321 height = image .getHeight ();
322+
323+ if (height > CONFIG .maxSize || width > CONFIG .maxSize ) {
324+ var scaleDown = Math .min (CONFIG .maxSize / (double ) height , CONFIG .maxSize / (double ) width );
325+ width = (int ) (width * scaleDown );
326+ height = (int ) (height * scaleDown );
327+ }
305328 }
306329
307330 int finalHeight = height ;
308331 int finalWidth = width ;
309332
310- if (finalHeight > CONFIG .maxSize || finalWidth > CONFIG .maxSize ) {
311- source .sendSuccess (() -> Component .literal ("Map size exceeds maximum allowed (" + CONFIG .maxSize + "x" + CONFIG .maxSize + "), was " + finalWidth + "x" + finalHeight ), false );
312- return null ;
313- }
314333 source .sendSuccess (() -> Component .literal ("Converting into maps..." ), false );
315334
316335 CompletableFuture .supplyAsync (() -> MapRenderer .render (image , mode , finalWidth , finalHeight )).thenAcceptAsync (mapImage -> {
0 commit comments