Skip to content

Commit

Permalink
Fix ArrayIndexOutOfBoundsException when dividing gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyJayJay committed Jul 31, 2020
1 parent 8db9fcb commit c3a6c71
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.github.johnnyjayjay.spigotmaps.rendering.SimpleTextRenderer;

import javax.imageio.ImageIO;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -121,7 +119,7 @@ public static List<GifImage> divideIntoMapSizedParts(GifImage gif, boolean crop)
);
}

int parts = newFrames[0].getImage().getWidth() / MINECRAFT_MAP_SIZE.width;
int parts = square(newFrames[0].getImage().getWidth() / MINECRAFT_MAP_SIZE.width);
GifImage.Frame[][] dividedParts = new GifImage.Frame[parts][newFrames.length];
for (int i = 0; i < newFrames.length; i++) {
GifImage.Frame frame = newFrames[i];
Expand All @@ -133,6 +131,10 @@ public static List<GifImage> divideIntoMapSizedParts(GifImage gif, boolean crop)
return Arrays.stream(dividedParts).map(Arrays::asList).map(GifImage::create).collect(Collectors.toList());
}

private static int square(int x) {
return x * x;
}

/**
* Takes an image and resizes it in a way that the parts returned by this method can be put together
* to form the whole image.
Expand Down

0 comments on commit c3a6c71

Please sign in to comment.