Search in sources :

Example 1 with TFile

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 "";
}
Also used : TFile(net.java.truevfs.access.TFile) Matcher(java.util.regex.Matcher)

Example 2 with TFile

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;
}
Also used : TFile(net.java.truevfs.access.TFile) TFileOutputStream(net.java.truevfs.access.TFileOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 3 with TFile

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;
}
Also used : TFile(net.java.truevfs.access.TFile) BufferedImage(java.awt.image.BufferedImage)

Example 4 with TFile

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);
}
Also used : TFile(net.java.truevfs.access.TFile) CardDownloadData(org.mage.plugins.card.images.CardDownloadData)

Example 5 with TFile

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 "";
}
Also used : TFile(net.java.truevfs.access.TFile)

Aggregations

TFile (net.java.truevfs.access.TFile)14 BufferedImage (java.awt.image.BufferedImage)4 IOException (java.io.IOException)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 Writer (java.io.Writer)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 Matcher (java.util.regex.Matcher)1 CardInfo (mage.cards.repository.CardInfo)1 TFileOutputStream (net.java.truevfs.access.TFileOutputStream)1 TFileReader (net.java.truevfs.access.TFileReader)1 TFileWriter (net.java.truevfs.access.TFileWriter)1 FsSyncException (net.java.truevfs.kernel.spec.FsSyncException)1 CardDownloadData (org.mage.plugins.card.images.CardDownloadData)1