use of net.java.truevfs.access.TFile in project mage by magefree.
the class ImageCache method getFilePath.
public static String getFilePath(CardView card, int width) {
String key = getKey(card, card.getName(), Integer.toString(width));
boolean usesVariousArt = false;
if (key.matches(".*#usesVariousArt.*")) {
usesVariousArt = true;
key = key.replace("#usesVariousArt", "");
}
boolean thumbnail = false;
if (key.matches(".*#thumb.*")) {
thumbnail = true;
key = key.replace("#thumb", "");
}
Matcher m = KEY_PATTERN.matcher(key);
if (m.matches()) {
String name = m.group(1);
String set = m.group(2);
Integer type = Integer.parseInt(m.group(3));
String collectorId = m.group(4);
if (collectorId.equals("null")) {
collectorId = "0";
}
String tokenSetCode = m.group(5);
String tokenDescriptor = m.group(6);
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor);
String path;
if (collectorId.isEmpty() || "0".equals(collectorId) || !tokenDescriptor.isEmpty()) {
// tokenDescriptor for embalm ability
info.setToken(true);
path = CardImageUtils.generateTokenImagePath(info);
if (path == null) {
// try token image from card
CardDownloadData newInfo = new CardDownloadData(info);
newInfo.setToken(false);
path = CardImageUtils.buildImagePathToCard(newInfo);
TFile tokenFile = getTFile(path);
if (tokenFile == null || !tokenFile.exists()) {
// token empty token image
// TODO: replace empty token by other default card, not cardback
path = CardImageUtils.buildImagePathToDefault(DirectLinksForDownload.cardbackFilename);
}
}
} else {
path = CardImageUtils.buildImagePathToCard(info);
}
if (thumbnail && path.endsWith(".jpg")) {
return buildThumbnailPath(path);
}
return path;
}
return "";
}
use of net.java.truevfs.access.TFile in project mage by magefree.
the class ImageCache method makeThumbnail.
public static BufferedImage makeThumbnail(BufferedImage original, String path) {
BufferedImage image = TransformedImageCache.getResizedImage(original, Constants.THUMBNAIL_SIZE_FULL.width, Constants.THUMBNAIL_SIZE_FULL.height);
TFile imageFile = getTFile(path);
if (imageFile == null) {
return null;
}
try {
try (TFileOutputStream outputStream = new TFileOutputStream(imageFile)) {
String format = image.getColorModel().getNumComponents() > 3 ? "png" : "jpg";
ImageIO.write(image, format, outputStream);
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
imageFile.delete();
}
return image;
}
use of net.java.truevfs.access.TFile in project mage by magefree.
the class ImageCache method getManifestImage.
public static BufferedImage getManifestImage() {
// TODO: replace by manifestest image
CardDownloadData info = new CardDownloadData("Manifest", "FRF", "0", false, 0, "FRF", "");
info.setToken(true);
String path = CardImageUtils.generateTokenImagePath(info);
if (path == null) {
return null;
}
TFile file = getTFile(path);
BufferedImage image = loadImage(file);
image = getRoundCorner(image);
return image;
}
use of net.java.truevfs.access.TFile in project mage by magefree.
the class CardImageUtils method searchForCardImage.
private static String searchForCardImage(CardDownloadData card) {
TFile file;
String path;
CardDownloadData c = new CardDownloadData(card);
c.setSet(card.getTokenSetCode());
path = getTokenImagePath(c);
file = new TFile(path);
if (file.exists()) {
pathCache.put(card, path);
return path;
}
return generateTokenDescriptorImagePath(card);
}
use of net.java.truevfs.access.TFile in project mage by magefree.
the class CardImageUtils method generateTokenDescriptorImagePath.
public static String generateTokenDescriptorImagePath(CardDownloadData card) {
String straightImageFile = buildImagePathToTokenDescriptor(card);
TFile file = new TFile(straightImageFile);
if (file.exists()) {
return straightImageFile;
}
straightImageFile = straightImageFile.replaceFirst("\\.[0-9]+\\.[0-9]+", ".X.X");
file = new TFile(straightImageFile);
if (file.exists()) {
return straightImageFile;
}
straightImageFile = straightImageFile.replaceFirst("\\.X\\.X", ".S.S");
file = new TFile(straightImageFile);
if (file.exists()) {
return straightImageFile;
}
return "";
}
Aggregations