Beispiel #1
0
def GenerateCard5Titles(Language, item):

    card = Image.new("RGBA", (384, 50))

    canvas = ImageDraw.Draw(card)

    if Language == "ja":
        font = ImageFont.truetype('assets/Fonts/NotoSansJP-Bold.otf', 15)
    elif Language == "ko":
        font = ImageFont.truetype('assets/Fonts/NotoSansKR-Regular.otf', 15)
    else:
        font = ImageFont.truetype('assets/Fonts/burbanksmall-black.otf', 15)

    title = item["title"]
    title = title.upper()

    icon = item["image"]
    icon = ImageUtil.Download(item, icon)
    icon = ImageUtil.RatioResize(item, icon, 384, 216)
    card.paste(icon, ImageUtil.CenterX(item, icon.width, card.width))

    ### 1920 * 1080 = 384
    try:
        TINT_COLOR = (0, 0, 205)  # Black
        TRANSPARENCY = 0.7  # Degree of transparency, 0-100%
        OPACITY = int(255 * TRANSPARENCY)

        cardBottom = Image.new("RGBA", (384, 360), TINT_COLOR)
        draw = ImageDraw.Draw(cardBottom)
        draw.rectangle(((384, 360), (0, 0)), fill=TINT_COLOR + (OPACITY, ))
    except Exception as e:
        print(e)
    card.paste(cardBottom, (0, 0), cardBottom)

    textWidth, _ = font.getsize(title)
    if textWidth >= 364:
        # Ensure that the item name does not overflow
        if Language == "ja":
            font, textWidth = ImageUtil.FitTextX2(item, title, 16, 1920)
        elif Language == "ko":
            font, textWidth = ImageUtil.FitTextX1(item, title, 16, 1920)
        else:
            font, textWidth = ImageUtil.FitTextX(item, title, 16, 1920)
    canvas.text(
        ImageUtil.CenterX(item, textWidth, card.width, 15),
        title,
        (255, 255, 255),
        font=font,
    )

    return card
    def GenerateCard(self, item: dict):
        """Return the card image for the provided Fortnite Item Shop item."""

        try:
            name = item["items"][0]["name"]
            rarity = item["items"][0]["rarity"]["value"]
            category = item["items"][0]["type"]["value"]
            price = item["finalPrice"]
            if item["items"][0]["images"]["featured"] is not None:
                icon = item["items"][0]["images"]["featured"]
            else:
                icon = item["items"][0]["images"]["icon"]
        except Exception as e:
            log.error(f"Failed to parse item {name}, {e}")

            return

        if rarity == "frozen":
            blendColor = (148, 223, 255)
        elif rarity == "lava":
            blendColor = (234, 141, 35)
        elif rarity == "legendary":
            blendColor = (211, 120, 65)
        elif rarity == "dark":
            blendColor = (251, 34, 223)
        elif rarity == "starwars":
            blendColor = (231, 196, 19)
        elif rarity == "marvel":
            blendColor = (197, 51, 52)
        elif rarity == "slurp":
            blendColor = (0, 242, 213)
        elif rarity == "dc":
            blendColor = (84, 117, 199)
        elif rarity == "icon":
            blendColor = (54, 183, 183)
        elif rarity == "shadow":
            blendColor = (113, 113, 113)
        elif rarity == "epic":
            blendColor = (177, 91, 226)
        elif rarity == "rare":
            blendColor = (73, 172, 242)
        elif rarity == "uncommon":
            blendColor = (96, 170, 58)
        elif rarity == "common":
            blendColor = (190, 190, 190)
        elif rarity == "gaminglegends":
            blendColor = (42, 0, 168)
        else:
            blendColor = (255, 255, 255)

        card = Image.new("RGBA", (300, 545))

        try:
            layer = ImageUtil.Open(
                self, f"shopitem_background_{rarity}.png").convert("RGBA")
        except FileNotFoundError:
            log.warn(
                f"Failed to open shopitem_background_{rarity}.png, defaulted to Common"
            )
            layer = ImageUtil.Open(self, "shopitem_background_common.png")

        card.paste(layer)

        icon = ImageUtil.Download(self, icon).convert("RGBA")
        if (category == "outfit") or (category == "emote"):
            icon = ImageUtil.RatioResize(self, icon, 285, 365)
        elif category == "wrap":
            icon = ImageUtil.RatioResize(self, icon, 230, 310)
        else:
            icon = ImageUtil.RatioResize(self, icon, 310, 390)
        if (category == "outfit") or (category == "emote"):
            card.paste(icon, ImageUtil.CenterX(self, icon.width, card.width),
                       icon)
        else:
            card.paste(icon, ImageUtil.CenterX(self, icon.width, card.width,
                                               15), icon)

        if len(item["items"]) > 1:
            # Track grid position
            i = 0

            # Start at position 1 in items array
            for extra in item["items"][1:]:
                try:
                    extraRarity = extra["rarity"]["value"]
                    extraIcon = extra["images"]["smallIcon"]
                except Exception as e:
                    log.error(f"Failed to parse item {name}, {e}")

                    return

                try:
                    layer = ImageUtil.Open(
                        self, f"box_bottom_{extraRarity}.png").convert("RGBA")
                except FileNotFoundError:
                    log.warn(
                        f"Failed to open box_bottom_{extraRarity}.png, defaulted to Common"
                    )
                    layer = ImageUtil.Open(self, "box_bottom_common.png")

                card.paste(
                    layer,
                    (
                        (card.width - (layer.width + 9)),
                        (9 + ((i // 1) * (layer.height))),
                    ),
                )

                extraIcon = ImageUtil.Download(self, extraIcon).convert("RGBA")
                extraIcon = ImageUtil.RatioResize(self, extraIcon, 75, 75)

                card.paste(
                    extraIcon,
                    (
                        (card.width - (layer.width + 9)),
                        (9 + ((i // 1) * (extraIcon.height))),
                    ),
                    extraIcon,
                )

                try:
                    layer = ImageUtil.Open(self,
                                           f"box_faceplate_{extraRarity}.png")
                except FileNotFoundError:
                    log.warn(
                        f"Failed to open box_faceplate_{extraRarity}.png, defaulted to Common"
                    )
                    layer = ImageUtil.Open(self, "box_faceplate_common.png")

                card.paste(
                    layer,
                    (
                        (card.width - (layer.width + 9)),
                        (9 + ((i // 1) * (layer.height))),
                    ),
                    layer,
                )

                i += 1

        try:
            layer = ImageUtil.Open(
                self, f"shopitem_card_{rarity}.png").convert("RGBA")
        except FileNotFoundError:
            log.warn(
                f"Failed to open shopitem_card_{rarity}.png, defaulted to Common"
            )
            layer = ImageUtil.Open(self, "cshopitem_card_common.png")

        card.paste(layer, layer)

        card.paste(layer, layer)

        canvas = ImageDraw.Draw(card)

        font = ImageUtil.Font(self, 33)
        textWidth, _ = font.getsize(f"{category} {rarity}")
        canvas.text(
            ImageUtil.CenterX(self, textWidth, card.width, 385),
            f"",
            blendColor,
            font=font,
        )

        vbucks = ImageUtil.Open(self, "vbucks_card.png").convert("RGBA")
        vbucks = ImageUtil.RatioResize(self, vbucks, 49, 49)

        price = str(f"{price:,}")
        textWidth, _ = font.getsize(price)
        canvas.text(
            ImageUtil.CenterX(self, ((textWidth + 15) - vbucks.width),
                              card.width, 450),
            price,
            blendColor,
            font=font,
        )

        card.paste(
            vbucks,
            ImageUtil.CenterX(self, (vbucks.width + (textWidth - 290)),
                              card.width, 436),
            vbucks,
        )

        font = ImageUtil.Font(self, 56)
        textWidth, _ = font.getsize(name)
        change = 0
        if textWidth >= 270:
            # Ensure that the item name does not overflow
            font, textWidth, change = ImageUtil.FitTextX(self, name, 56, 260)
        canvas.text(
            ImageUtil.CenterX(self, textWidth, card.width,
                              (380 + (change / 2))),
            name,
            (255, 255, 255),
            font=font,
        )

        return card
Beispiel #3
0
    def GenerateCard(self, item: dict):
        """Return the card image for the provided Fortnite Item Shop item."""

        try:
            name = item["items"][0]["name"]
            rarity = item["items"][0]["rarity"]
            displayrarity = item["items"][0]["displayRarity"]
            category = item["items"][0]["type"]
            price = str(item["finalPrice"])
            if (category == "outfit") or (category == "wrap"):
                if item["items"][0]["images"]["featured"] is not None:
                    icon = item["items"][0]["images"]["featured"]["url"]
                else:
                    icon = item["items"][0]["images"]["icon"]["url"]
            else:
                icon = item["items"][0]["images"]["icon"]["url"]
        except Exception as e:
            Log.Error(self, f"Failed to parse item {name}, {e}")

            return

        if rarity == "common":
            blendColor = (190, 190, 190)
        elif rarity == "uncommon":
            blendColor = (96, 170, 58)
        elif rarity == "rare":
            blendColor = (73, 172, 242)
        elif rarity == "epic":
            blendColor = (177, 91, 226)
        elif rarity == "legendary":
            blendColor = (211, 120, 65)
        elif rarity == "marvel":
            blendColor = (197, 51, 52)
        elif rarity == "dark":
            blendColor = (251, 34, 223)
        elif rarity == "dc":
            blendColor = (84, 117, 199)
        else:
            blendColor = (255, 255, 255)

        card = Image.new("RGBA", (300, 545))

        try:
            layer = ImageUtil.Open(self, f"card_top_{rarity.lower()}.png")
        except FileNotFoundError:
            Log.Warn(
                self,
                f"Failed to open card_top_{rarity.lower()}.png, defaulted to Common",
            )
            layer = ImageUtil.Open(self, "card_top_common.png")

        card.paste(layer)

        if category == 'glider':
            x = 285 / 1.1
            y = 365 / 1.8
            distanceTop = 60
        elif category == 'music':
            x = 285 / 1.1
            y = 365 / 1.6
            distanceTop = 55
        elif category == 'pickaxe':
            x = 285 / 1.1
            y = 365 / 1.3
            distanceTop = 40
        elif category == 'wrap':
            x = 285 / 1.1
            y = 365 / 1.3
            distanceTop = 40
        else:
            x = 285
            y = 365
            distanceTop = 10

        icon = ImageUtil.Download(self, icon)
        icon = ImageUtil.RatioResize(self, icon, x, y)
        card.paste(
            icon,
            ImageUtil.CenterX(self,
                              icon.width,
                              card.width,
                              distanceTop=distanceTop), icon)

        if len(item["items"]) > 1:
            # Track grid position
            i = 0

            # Start at position 1 in items array
            for extra in item["items"][1:]:
                try:
                    extraRarity = extra["rarity"]
                    extraIcon = extra["images"]["smallIcon"]["url"]
                except Exception as e:
                    Log.Error(self, f"Failed to parse item {name}, {e}")

                    return

                try:
                    layer = ImageUtil.Open(
                        self, f"box_bottom_{extraRarity.lower()}.png")
                except FileNotFoundError:
                    Log.Warn(
                        self,
                        f"Failed to open box_bottom_{extraRarity.lower()}.png, defaulted to Common",
                    )
                    layer = ImageUtil.Open(self, "box_bottom_common.png")

                card.paste(layer, (17, (17 + ((i // 1) * (layer.height)))))

                extraIcon = ImageUtil.Download(self, extraIcon)
                extraIcon = ImageUtil.RatioResize(self, extraIcon, 75, 75)

                card.paste(extraIcon,
                           (17, (17 + ((i // 1) * (extraIcon.height)))),
                           extraIcon)

                try:
                    layer = ImageUtil.Open(
                        self, f"box_faceplate_{extraRarity.lower()}.png")
                except FileNotFoundError:
                    Log.Warn(
                        self,
                        f"Failed to open box_faceplate_{extraRarity.lower()}.png, defaulted to Common",
                    )
                    layer = ImageUtil.Open(self, "box_faceplate_common.png")

                card.paste(layer, (17, (17 + ((i // 1) * (layer.height)))),
                           layer)

                i += 1

        try:
            layer = ImageUtil.Open(self,
                                   f"card_faceplate_{rarity.lower()}.png")
        except FileNotFoundError:
            Log.Warn(
                self,
                f"Failed to open card_faceplate_{rarity.lower()}.png, defaulted to Common",
            )
            layer = ImageUtil.Open(self, "card_faceplate_common.png")

        card.paste(layer, layer)

        try:
            layer = ImageUtil.Open(self, f"card_bottom_{rarity.lower()}.png")
        except FileNotFoundError:
            Log.Warn(
                self,
                f"Failed to open card_bottom_{rarity.lower()}.png, defaulted to Common",
            )
            layer = ImageUtil.Open(self, "card_bottom_common.png")

        card.paste(layer, layer)

        canvas = ImageDraw.Draw(card)

        font = ImageUtil.Font(self, 30)
        textWidth, _ = font.getsize(f"{displayrarity} {category.title()}")
        canvas.text(
            ImageUtil.CenterX(self, textWidth, card.width, 385),
            f"{displayrarity} {category.title()}",
            blendColor,
            font=font,
        )

        vbucks = ImageUtil.Open(self, "vbucks.png")
        vbucks = ImageUtil.RatioResize(self, vbucks, 25, 25)

        textWidth, _ = font.getsize(price)
        canvas.text(
            ImageUtil.CenterX(self, ((textWidth - 5) - vbucks.width),
                              card.width, 495),
            price,
            (255, 255, 255),
            font=font,
        )

        card.paste(
            vbucks,
            ImageUtil.CenterX(self, (vbucks.width + (textWidth + 5)),
                              card.width, 495),
            vbucks,
        )

        font = ImageUtil.Font(self, 56)
        textWidth, _ = font.getsize(name)
        if textWidth >= 270:
            # Ensure that the item name does not overflow
            font, textWidth = ImageUtil.FitTextX(self, name, 56, 265)
        canvas.text(
            ImageUtil.CenterX(self, textWidth, card.width, 425),
            name,
            (255, 255, 255),
            font=font,
        )

        return card
Beispiel #4
0
    def GenerateCard(self, item: dict):
        """Return the card image for the provided Fortnite Item Shop item."""

        try:
            name = item["name"].lower()
            rarity = item["rarity"].lower()
            category = item["type"].lower()
            price = item["price"]


            if (item["image"]):
                icon = item["image"]
            else:
                icon = item["icon"]

        except Exception as e:
            log.error(f"Failed to parse item {name}, {e}")

            return

        if rarity == "frozen series":
            blendColor = (148, 223, 255)
            rarity = "Frozen"
        elif rarity == "lava series":
            blendColor = (234, 141, 35)
            rarity = "Lava"
        elif rarity == "legendary":
            blendColor = (211, 120, 65)
            rarity = "Legendary"
        elif rarity == "slurp series":
            blendColor = (0, 233, 176)
            rarity = "Slurp"
        elif rarity == "dark":
            blendColor = (251, 34, 223)
            rarity = "Dark"
        elif rarity == "star wars series":
            blendColor = (231, 196, 19)
            rarity = "Star Wars"
        elif rarity == "marvel":
            blendColor = (197, 51, 52)
            rarity = "Marvel"
        elif rarity == "dc":
            blendColor = (84, 117, 199)
            rarity = "DC"
        elif rarity == "icon series":
            blendColor = (54, 183, 183)
            rarity = "Icon"
        elif rarity == "shadow series":
            blendColor = (113, 113, 113)
            rarity = "Shadow"
        elif rarity == "platform series":
            blendColor = (117,129,209)
            rarity = "GamingLegends"
        elif rarity == "epic":
            blendColor = (177, 91, 226)
            rarity = "Epic"
        elif rarity == "rare":
            blendColor = (73, 172, 242)
            rarity = "Rare"
        elif rarity == "uncommon":
            blendColor = (96, 170, 58)
            rarity = "Uncommon"
        elif rarity == "common":
            blendColor = (190, 190, 190)
            rarity = "Common"
        else:
            blendColor = (255, 255, 255)
            rarity = "Unknown"

        card = Image.new("RGBA", (310, 510))

        try:
            layer = ImageUtil.Open(
                self, f"./shopTemplates/{rarity.capitalize()}BG.png")
        except FileNotFoundError:
            log.warn(
                f"Failed to open {rarity.capitalize()}BG.png, defaulted to Common")
            layer = ImageUtil.Open(self, "./shopTemplates/CommonBG.png")
        card.paste(layer)

        icon = ImageUtil.Download(self, icon)
        if (category == "outfit") or (category == "emote"):
            icon = ImageUtil.RatioResize(self, icon, 285, 365)
        elif category == "wrap":
            icon = ImageUtil.RatioResize(self, icon, 230, 310)
        else:
            icon = ImageUtil.RatioResize(self, icon, 310, 390)
        if (category == "outfit") or (category == "emote"):
            card.paste(icon, ImageUtil.CenterX(self, icon.width, card.width), icon)
        else:
            card.paste(icon, ImageUtil.CenterX(self, icon.width, card.width, 15), icon)

        try:
            layer = ImageUtil.Open(
                self, f"./shopTemplates/{rarity.capitalize()}OV.png")
        except FileNotFoundError:
            log.warn(
                f"Failed to open {rarity.capitalize()}OV.png, defaulted to Common")
            layer = ImageUtil.Open(self, "./shopTemplates/CommonOV.png")

        card.paste(layer, layer)

        canvas = ImageDraw.Draw(card)

        vbucks = ImageUtil.Open(self, "vbucks.png")
        vbucks = ImageUtil.RatioResize(self, vbucks, 40, 40)

        font = ImageUtil.Font(self, 40)
        price = str(f"{price:,}")
        textWidth, _ = font.getsize(price)

        canvas.text(ImageUtil.CenterX(self, ((textWidth - 5) - vbucks.width), card.width, 347), price, (255, 255, 255), font=font)
        card.paste(vbucks,ImageUtil.CenterX(self, (vbucks.width + (textWidth + 5)), card.width, 350),vbucks)

        font = ImageUtil.Font(self, 40)
        itemName = name.upper().replace(" OUTFIT", "").replace(" PICKAXE", "").replace(" BUNDLE", "")

        if(category == "bundle"):
            itemName = name.upper().replace(" BUNDLE", "")

        textWidth, _ = font.getsize(itemName)

        change = 0
        if textWidth >= 280:
            # Ensure that the item name does not overflow
            font, textWidth, change = ImageUtil.FitTextX(self, itemName, 40, 260)
        canvas.text(ImageUtil.CenterX(self, textWidth, card.width, (400 + (change / 2))), itemName, (255, 255, 255), font=font)
      
        font = ImageUtil.Font(self, 40)
        textWidth, _ = font.getsize(f"{category.upper()}")
        
        change = 0
        if textWidth >= 280:
            # Ensure that the item rarity/type does not overflow
            font, textWidth, change = ImageUtil.FitTextX(self, f"{category.upper()}", 30, 260)
        canvas.text(ImageUtil.CenterX(self, textWidth, card.width, (450 + (change / 2))), f"{category.upper()}", blendColor, font=font)
        return card