コード例 #1
0
ファイル: emporium.py プロジェクト: EthanC/Emporium
    def BuildCard(self: Any, bundle: Dict[str, Any], font: Any) -> Image.Image:
        """Generate a stylized image for the specified Bundle."""

        imageBaseUrl: str = "https://titles.trackercdn.com/modern-warfare/db/images/"

        card: Image.Image = Utility.OpenImage(self, "card_container.png")

        billboardUrl: str = imageBaseUrl + bundle.get("billboard") + ".png"
        billboard: Image.Image = Utility.DownloadImage(self, billboardUrl)
        billboard = Utility.ResizeImage(self, billboard, height=card.height)
        billboard = billboard.crop((258, 0, 1263, card.height))

        gradient: Image.Image = Utility.OpenImage(self, "card_gradient.png")
        billboard.alpha_composite(gradient)

        card.paste(billboard, Utility.CenterX(self, billboard.width,
                                              card.width), card)

        logoUrl: str = imageBaseUrl + bundle.get("logo") + ".png"
        logo: Image.Image = Utility.DownloadImage(self, logoUrl)
        logo = Utility.ResizeImage(self, logo, width=360)
        card.alpha_composite(logo, (25, 25))

        border: Image.Image = Utility.OpenImage(self, "card_border.png")
        card.alpha_composite(border)

        tag: Image.Image = Utility.OpenImage(self, "price_container.png")
        canvas: Any = ImageDraw.Draw(tag)
        price: Union[int, str] = bundle.get("price")
        canvas.text((50, 5), f"{price:,}", (255, 255, 255), font)
        card.alpha_composite(tag, (25, (card.height - tag.height - 25)))

        return card
コード例 #2
0
ファイル: emporium.py プロジェクト: EthanC/Emporium
    def BuildImage(self: Any, data: Dict[str, Any]) -> bool:
        """Generate a stylized image for the provided Store data."""

        background: Tuple[int, int, int] = tuple(
            self.config["appearance"].get("background"))
        text: Tuple[int, int,
                    int] = tuple(self.config["appearance"].get("text"))

        fontName: str = self.config["appearance"].get("font")
        font72 = Utility.GetTTF(self, 72, fontName)
        font32 = Utility.GetTTF(self, 32, fontName)

        featured: List[Dict[str, Any]] = data.get("featured")
        operators: List[Dict[str, Any]] = data.get("operators")
        blueprints: List[Dict[str, Any]] = data.get("blueprints")

        dimensions: Tuple[int, int] = Emporium.CalculateDimensions(
            self, featured, operators, blueprints)

        store: Image = Image.new("RGBA", (dimensions[0], dimensions[1]))
        canvas: Any = ImageDraw.Draw(store)

        store.paste(background, (0, 0, store.width, store.height))

        gameLogo: Image.Image = Utility.OpenImage(self, "game_logo.png")
        gameLogo = Utility.ResizeImage(self, gameLogo, width=1000)
        store.paste(gameLogo,
                    Utility.CenterX(self, gameLogo.width, store.width, 50),
                    gameLogo)

        prettyDate: str = data.get("updateDate")
        textWidth, _ = font72.getsize(prettyDate)
        canvas.text(Utility.CenterX(self, textWidth, store.width, 275),
                    prettyDate, text, font72)

        sectionX: int = 0
        sectionY: int = 500
        cardY: int = 0
        cardX: int = 0

        if len(featured) > 0:
            canvas.text((50, sectionY), "Featured", text, font72)

            i: int = 0

            for bundle in featured:
                card: Image.Image = Emporium.BuildCard(self, bundle, font32)

                cardX: int = sectionX + (50 + ((i % 2) * (card.width + 50)))
                cardY: int = 500 + (75 + 50) + (i // 2) * (card.height + 50)
                store.paste(card, (cardX, cardY), card)

                i += 1

            sectionX += 50 + (1005 * 2) + 50

        if len(operators) > 0:
            canvas.text((50 + sectionX, sectionY), "Operators & Identity",
                        text, font72)

            i: int = 0

            for bundle in operators:
                card: Image.Image = Emporium.BuildCard(self, bundle, font32)

                cardX: int = sectionX + (50 + ((i % 2) * (card.width + 50)))
                cardY: int = 500 + (75 + 50) + (i // 2) * (card.height + 50)
                store.paste(card, (cardX, cardY), card)

                i += 1

            sectionX += 50 + (1005 * 2) + 50

        if len(blueprints) > 0:
            canvas.text((50 + sectionX, sectionY), "Blueprints", text, font72)

            i: int = 0

            for bundle in blueprints:
                card: Image.Image = Emporium.BuildCard(self, bundle, font32)

                cardX: int = sectionX + (50 + ((i % 2) * (card.width + 50)))
                cardY: int = 500 + (75 + 50) + (i // 2) * (card.height + 50)
                store.paste(card, (cardX, cardY), card)

                i += 1

            sectionX += 50 + (1005 * 2) + 50

        store.save("store.png", optimize=True)

        log.info("Generated the Store image")

        return True