mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-02-21 13:51:22 +01:00
* NEW: Added width and height parameters to the resize option.
This commit is contained in:
parent
e89f9007a7
commit
47fb9737cb
@ -42,6 +42,7 @@ public class NewCommand extends IoMCommand
|
||||
final Player player = playerSender();
|
||||
boolean scaling = false;
|
||||
URL url;
|
||||
int width = 0, height = 0;
|
||||
|
||||
if(args.length < 1) throwInvalidArgument(I.t("You must give an URL to take the image from."));
|
||||
|
||||
@ -57,11 +58,17 @@ public class NewCommand extends IoMCommand
|
||||
|
||||
if(args.length >= 2)
|
||||
{
|
||||
if(args[1].equals("resize")) scaling = true;
|
||||
if(args[1].equals("resize")) {
|
||||
scaling = true;
|
||||
if(args.length >= 4) {
|
||||
width = Integer.parseInt(args[2]);
|
||||
height = Integer.parseInt(args[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
info(I.t("Rendering..."));
|
||||
ImageRendererExecutor.Render(url, scaling, player.getUniqueId(), new WorkerCallback<ImageMap>()
|
||||
ImageRendererExecutor.Render(url, scaling, player.getUniqueId(), width, height, new WorkerCallback<ImageMap>()
|
||||
{
|
||||
@Override
|
||||
public void finished(ImageMap result)
|
||||
|
@ -42,7 +42,7 @@ import java.util.concurrent.Future;
|
||||
@WorkerAttributes (name = "Image Renderer", queriesMainThread = true)
|
||||
public class ImageRendererExecutor extends Worker
|
||||
{
|
||||
static public void Render(final URL url, final boolean scaling, final UUID playerUUID, WorkerCallback<ImageMap> callback)
|
||||
static public void Render(final URL url, final boolean scaling, final UUID playerUUID, final int width, final int height, WorkerCallback<ImageMap> callback)
|
||||
{
|
||||
submitQuery(new WorkerRunnable<ImageMap>()
|
||||
{
|
||||
@ -65,11 +65,19 @@ public class ImageRendererExecutor extends Worker
|
||||
|
||||
if (image == null) throw new IOException(I.t("The given URL is not a valid image"));
|
||||
|
||||
if (scaling) return RenderSingle(image, playerUUID);
|
||||
if (scaling) return RenderScaled(image, playerUUID, width, height);
|
||||
else return RenderPoster(image, playerUUID);
|
||||
}
|
||||
}, callback);
|
||||
}
|
||||
|
||||
static private ImageMap RenderScaled(final BufferedImage image, final UUID playerUUID, final int width, final int height) throws Throwable {
|
||||
if(height <= 1 && width <= 1) {
|
||||
return RenderSingle(image, playerUUID);
|
||||
}
|
||||
final BufferedImage finalImage = ResizeImage(image, ImageMap.WIDTH * width, ImageMap.HEIGHT * height);
|
||||
return RenderPoster(finalImage, playerUUID);
|
||||
}
|
||||
|
||||
static private ImageMap RenderSingle(final BufferedImage image, final UUID playerUUID) throws Throwable
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user