{ "cells": [ { "cell_type": "markdown", "id": "427243b8", "metadata": {}, "source": [ "# Generate Transparent Image Assets for Campaigns and Presentations\n", "\n", "A great image should work on any background. Transparent image assets (in preview) make it easy to reuse the same visuals across campaigns, websites, presentations, and product catalogs without white boxes or manual background removal.\n", "\n", "This cookbook covers four customer use cases:\n", "\n", "- **Seasonal e-commerce campaigns:** Generate transparent product images once and reuse them across storefront backgrounds, seasonal banners, and marketing layouts.\n", "- **Branded enterprise presentations:** Generate transparent charts that blend directly into required PowerPoint themes and gradient slide backgrounds.\n", "- **Design-template assets:** Generate app icons, stickers, and decorative elements that users can place on any template or background.\n", "- **Print-on-demand merchandise:** Apply one transparent print design to different blank garments and product mockups." ] }, { "cell_type": "markdown", "id": "614b083e", "metadata": {}, "source": [ "## Set up\n", "\n", "Install the Python packages with `pip install openai pillow`, and set `OPENAI_API_KEY` in your environment. You will also need access to a transparency-capable image model and Codex to build the website.\n", "\n", "This example uses `gpt-image-2` and requests PNG output with `background=\"transparent\"`.\n", "\n", "For more background, see the [GPT Image Generation Models Prompting Guide](https://developers.openai.com/cookbook/examples/multimodal/image-gen-models-prompting-guide), the [OpenAI models page](https://developers.openai.com/api/docs/models), and the [image generation guide](https://developers.openai.com/api/docs/guides/image-generation)." ] }, { "cell_type": "code", "execution_count": null, "id": "9586fe47", "metadata": {}, "outputs": [], "source": [ "import base64\n", "import os\n", "from pathlib import Path\n", "\n", "from openai import OpenAI\n", "from PIL import Image\n", "\n", "if not os.getenv(\"OPENAI_API_KEY\"):\n", " raise RuntimeError(\"Set OPENAI_API_KEY before running this notebook.\")\n", "\n", "IMAGE_MODEL = \"gpt-image-2\"\n", "\n", "client = OpenAI()\n", "asset_dir = Path(\"images/transparent-image-assets\")\n", "asset_dir.mkdir(parents=True, exist_ok=True)" ] }, { "cell_type": "markdown", "id": "0aab78de", "metadata": {}, "source": [ "## Use case 1: Seasonal e-commerce campaigns\n", "\n", "A fictional home-fragrance brand wants to reuse one product collection across multiple seasonal storefronts. Generate transparent product shots once, then place the same assets over different campaign backgrounds without cutting them out by hand.\n", "\n", "### 1.1 Define the original product prompts\n", "\n", "The website uses four products from the same fictional home-fragrance brand. Each original product description is followed by the same brand-and-transparency instructions to keep the collection visually consistent.\n", "\n", "**Note:** Prompt instructions take priority over `background=\"transparent\"`. If the prompt describes a backdrop, scene, color, or other background, the model may generate that background instead of producing transparency. Keep the prompt focused on an isolated subject and explicitly request a transparent background." ] }, { "cell_type": "code", "execution_count": null, "id": "3caa3703", "metadata": {}, "outputs": [], "source": [ "brand_prompt = (\n", " \"One object from STILLROOM, an understated luxury botanical home-fragrance \"\n", " \"atelier: artisanal warm amber and honey-tinted hand-blown glass, subtle \"\n", " \"brushed brass hardware, natural ivory cotton cord, quiet \"\n", " \"Japanese-Scandinavian restraint, warm side-lit editorial studio \"\n", " \"photography, photorealistic micro-detail, immaculate premium campaign \"\n", " \"quality. Full object completely visible and generously padded. Preserve \"\n", " \"every natural transparency, refraction, translucent layer and fine \"\n", " \"material edge. Output an isolated object on actual fully transparent \"\n", " \"alpha; no backdrop, no rectangle, no plinth, no cast shadow, no readable \"\n", " \"writing, no label text, no watermark.\"\n", ")\n", "\n", "products = {\n", " \"amber-parfum\": (\n", " \"A sculptural substantial clear honey-amber faceted glass \"\n", " \"eau-de-parfum bottle, slender rectangular body with softly rounded \"\n", " \"shoulders, heavy clear crystal cap, a small delicate sheer ivory \"\n", " \"organza ribbon loosely tied around the brushed brass neck with one \"\n", " \"translucent airy tail floating naturally; visible golden fragrance \"\n", " \"liquid and beautifully realistic glass refraction.\"\n", " ),\n", " \"botanical-oil\": (\n", " \"A slim elegant cylindrical deep honey-amber transparent hand-blown \"\n", " \"glass botanical body-oil bottle, tall slender polished brushed-brass \"\n", " \"dropper cap with tiny ivory rubber bulb, translucent pale golden \"\n", " \"botanical oil inside and a tiny delicate preserved sprig of green \"\n", " \"wild fennel visible suspended within the liquid; subtle refraction, \"\n", " \"premium apothecary design.\"\n", " ),\n", " \"reed-diffuser\": (\n", " \"A rounded low smoked-amber translucent glass home-fragrance diffuser \"\n", " \"vessel containing warm golden scented oil, topped by five naturally \"\n", " \"splayed very thin blonde rattan reeds and one extraordinarily \"\n", " \"delicate feathery dried pampas grass stem with fine hairlike wisps \"\n", " \"extending outward; realistic transparent glass and botanical fibers.\"\n", " ),\n", " \"garden-candle\": (\n", " \"A quiet luxurious handmade botanical candle in a thick heavy \"\n", " \"translucent smoky-amber and milky frosted glass tumbler, creamy \"\n", " \"natural ivory wax, one small gently glowing clean candle flame, \"\n", " \"delicate transparent-edged frosted glass rim, a loose fine ivory \"\n", " \"cotton cord tied around the vessel with one tiny dried eucalyptus \"\n", " \"sprig, perfect warm reflections.\"\n", " ),\n", "}" ] }, { "cell_type": "markdown", "id": "febbcc4a", "metadata": {}, "source": [ "### 1.2 Generate high-quality transparent PNGs" ] }, { "cell_type": "code", "execution_count": null, "id": "1dcdb8c1", "metadata": {}, "outputs": [], "source": [ "generate_images = True\n", "\n", "if generate_images:\n", " for filename, product_prompt in products.items():\n", " result = client.images.generate(\n", " model=IMAGE_MODEL,\n", " prompt=f\"{product_prompt} {brand_prompt}\",\n", " background=\"transparent\",\n", " size=\"1024x1536\",\n", " quality=\"high\",\n", " output_format=\"png\",\n", " )\n", "\n", " image_bytes = base64.b64decode(result.data[0].b64_json)\n", " (asset_dir / f\"{filename}.png\").write_bytes(image_bytes)" ] }, { "cell_type": "markdown", "id": "d2a71f95", "metadata": {}, "source": [ "### 1.3 Inspect the four generated products\n", "\n", "These are the original, unchanged transparent PNGs used on the campaign website.\n", "\n", "| Wild Fig Eau de Parfum | Meadow Botanical Oil |\n", "| --- | --- |\n", "| ![Wild Fig Eau de Parfum in a transparent amber-glass bottle](images/transparent-image-assets/amber-parfum.png) | ![Meadow Botanical Oil in a transparent amber-glass bottle](images/transparent-image-assets/botanical-oil.png) |\n", "| **Cedar Reed Diffuser** | **Garden After Rain Candle** |\n", "| ![Cedar Reed Diffuser with fine reeds and feathery pampas fibers](images/transparent-image-assets/reed-diffuser.png) | ![Garden After Rain Candle in a frosted amber-glass vessel](images/transparent-image-assets/garden-candle.png) |\n", "\n", "The next cell confirms that every file contains an alpha channel and reports how much of each image is fully transparent." ] }, { "cell_type": "code", "execution_count": null, "id": "17ce3701", "metadata": {}, "outputs": [], "source": [ "for filename in products:\n", " with Image.open(asset_dir / f\"{filename}.png\") as image:\n", " if image.mode != \"RGBA\":\n", " raise ValueError(f\"{filename}.png does not have an alpha channel.\")\n", "\n", " transparent_pixels = image.getchannel(\"A\").histogram()[0]\n", " total_pixels = image.width * image.height\n", " transparent_percentage = 100 * transparent_pixels / total_pixels\n", "\n", " print(\n", " f\"{filename}.png: {image.width}x{image.height}, \"\n", " f\"{transparent_percentage:.2f}% fully transparent\"\n", " )" ] }, { "cell_type": "markdown", "id": "d1727c3f", "metadata": {}, "source": [ "### 1.4 Build a seasonal campaign website with Codex\n", "\n", "Give Codex the four generated PNGs and ask it to build a single-page storefront for STILLROOM. The finished site places the same products over Spring, Summer, Autumn, and Winter campaign backgrounds, lets visitors switch between one product, two products, or the full collection, and includes a checkerboard view that makes the transparency visible.\n", "\n", "Run the following cell and paste its output into Codex alongside the image files." ] }, { "cell_type": "code", "execution_count": null, "id": "297bccff", "metadata": {}, "outputs": [], "source": [ "codex_prompt = '''\n", "Build a simple, responsive single-page campaign website for STILLROOM, a\n", "premium botanical home-fragrance brand, using these existing transparent PNGs:\n", "\n", "- images/transparent-image-assets/amber-parfum.png\n", "- images/transparent-image-assets/botanical-oil.png\n", "- images/transparent-image-assets/reed-diffuser.png\n", "- images/transparent-image-assets/garden-candle.png\n", "\n", "Show the heading \"One collection, four seasons.\" Add Spring, Summer, Autumn,\n", "and Winter controls that change the campaign background and seasonal copy.\n", "Include controls for one product, two products, and the full collection.\n", "Let visitors choose the featured product and rearrange the same transparent\n", "PNGs over every background. Add a \"Show transparency\" checkerboard toggle.\n", "Keep the page visually clean and centered on the products. Do not generate\n", "replacement images or run a separate background-removal step.\n", "'''.strip()\n", "\n", "print(codex_prompt)" ] }, { "cell_type": "markdown", "id": "3bdf4957", "metadata": {}, "source": [ "### 1.5 View the finished storefront\n", "\n", "The screenshots below show the same four transparent assets reused across different campaign backgrounds and product arrangements.\n", "\n", "**Spring campaign: the full four-product collection on a green background.**\n", "\n", "![STILLROOM spring campaign website showing all four transparent product images on a green background](images/transparent-image-assets/stillroom-spring-campaign.png)\n", "\n", "**Winter campaign: a two-product arrangement on a dark blue background.**\n", "\n", "![STILLROOM winter campaign website showing the reed diffuser and candle on a dark blue background](images/transparent-image-assets/stillroom-winter-campaign.png)\n", "\n", "#### Look closely at the difficult edges\n", "\n", "Switch between seasons and inspect the clear and frosted glass, the perfume bottle's sheer ribbon, the diffuser's thin reeds and hairlike pampas fibers, and the candle's fine cotton cord. Conventional background-removal tools can clip these details, add halos, or flatten translucent materials. Generating the alpha channel directly helps preserve those subtle edges when the same product is placed on very different backgrounds." ] }, { "cell_type": "markdown", "id": "c364918a", "metadata": {}, "source": [ "## Use case 2: Branded enterprise presentations\n", "\n", "Enterprise teams often have to use a required PowerPoint theme with a specific background color or gradient. An AI-generated chart with an opaque white background can clash with that theme, while a transparent PNG lets the slide's original background remain visible.\n", "\n", "### 2.1 Define the presentation scenario and mock business data\n", "\n", "The fictional Northstar Cloud board-review slide uses two data series: quarterly revenue and the regional distribution of qualified sales opportunities. These values are examples, not real company results.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "db892a10", "metadata": {}, "outputs": [], "source": [ "quarterly_revenue = {\n", " \"Q1\": 42,\n", " \"Q2\": 51,\n", " \"Q3\": 63,\n", " \"Q4\": 78,\n", "}\n", "\n", "regional_pipeline = {\n", " \"North America\": 46,\n", " \"Europe\": 29,\n", " \"APAC\": 25,\n", "}\n", "\n", "revenue_growth = (\n", " (quarterly_revenue[\"Q4\"] - quarterly_revenue[\"Q1\"])\n", " / quarterly_revenue[\"Q1\"]\n", ")\n", "\n", "print(f\"Quarterly revenue: {quarterly_revenue} USD millions\")\n", "print(f\"Regional pipeline: {regional_pipeline} percent\")\n", "print(f\"Q1-to-Q4 revenue growth: {revenue_growth:.0%}\")\n" ] }, { "cell_type": "markdown", "id": "684bc3d7", "metadata": {}, "source": [ "### 2.2 Define transparent chart prompts\n", "\n", "Ask for transparent areas across the entire chart, not just outside its silhouette. For a dark enterprise theme, also specify white or pale labels, bright brand-compatible colors, and no card, frame, panel, or filled plot area.\n", "\n", "The model receives the exact mock values, but generated image content is still raster artwork. Verify that labels, values, and proportions match the source data before using the charts. For production reporting where numerical precision is critical, render charts deterministically and use image generation for illustrations or other visual elements.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "bc41da87", "metadata": {}, "outputs": [], "source": [ "revenue_values = \", \".join(\n", " f\"{quarter} = ${amount}M\"\n", " for quarter, amount in quarterly_revenue.items()\n", ")\n", "\n", "pipeline_values = \", \".join(\n", " f\"{region} = {percentage}%\"\n", " for region, percentage in regional_pipeline.items()\n", ")\n", "\n", "chart_prompts = {\n", " \"quarterly-revenue-growth\": (\n", " \"Create one polished enterprise bar chart on a genuinely \"\n", " \"transparent background for a dark navy PowerPoint slide. \"\n", " f\"Use exactly four ascending bars with these values: {revenue_values}. \"\n", " \"Use cobalt blue, bright blue, electric azure, and turquoise bars. \"\n", " \"Add white quarter labels below each bar and white dollar-value \"\n", " \"labels above each bar. Add a subtle turquoise upward-trend arrow. \"\n", " \"Keep the plot area, grid, and space between bars transparent. \"\n", " \"Do not add a background, filled panel, frame, title, or card.\"\n", " ),\n", " \"regional-pipeline-mix\": (\n", " \"Create one polished enterprise doughnut chart on a genuinely \"\n", " \"transparent background for a dark navy PowerPoint slide. \"\n", " f\"Use exactly these regional pipeline shares: {pipeline_values}. \"\n", " \"Use turquoise, cobalt blue, and coral segments, with a white \"\n", " \"100% label in the center. Place a white-text regional legend \"\n", " \"beside the chart. Keep the doughnut center, legend area, and \"\n", " \"all surrounding space transparent. Do not add a background, \"\n", " \"filled panel, frame, title, or card.\"\n", " ),\n", "}\n" ] }, { "cell_type": "markdown", "id": "ff217ea3", "metadata": {}, "source": [ "### 2.3 Generate transparent PNG charts\n", "\n", "As in the product example, request `background=\"transparent\"` and `output_format=\"png\"`. A landscape size of `1536x1024` gives the charts room for their labels, and `quality=\"high\"` helps with small text.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "f1702dc8", "metadata": {}, "outputs": [], "source": [ "generate_charts = True\n", "\n", "if generate_charts:\n", " for filename, prompt in chart_prompts.items():\n", " result = client.images.generate(\n", " model=IMAGE_MODEL,\n", " prompt=prompt,\n", " background=\"transparent\",\n", " size=\"1536x1024\",\n", " quality=\"high\",\n", " output_format=\"png\",\n", " )\n", "\n", " image_bytes = base64.b64decode(result.data[0].b64_json)\n", " (asset_dir / f\"{filename}.png\").write_bytes(image_bytes)\n" ] }, { "cell_type": "markdown", "id": "b54bc23f", "metadata": {}, "source": [ "### 2.4 Inspect the generated chart assets\n", "\n", "The following files are separate transparent PNGs, ready to place on top of an enterprise slide theme.\n", "\n", "| Quarterly revenue | Regional pipeline mix |\n", "| --- | --- |\n", "| ![Transparent bar chart showing quarterly revenue increasing from 42 million to 78 million dollars](images/transparent-image-assets/quarterly-revenue-growth.png) | ![Transparent doughnut chart showing regional pipeline shares for North America, Europe, and APAC](images/transparent-image-assets/regional-pipeline-mix.png) |\n", "\n", "The next cell checks that both files contain real alpha channels and reports how much of each chart image is fully transparent.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "7f7db241", "metadata": {}, "outputs": [], "source": [ "for filename in chart_prompts:\n", " with Image.open(asset_dir / f\"{filename}.png\") as image:\n", " if image.mode != \"RGBA\":\n", " raise ValueError(f\"{filename}.png does not have an alpha channel.\")\n", "\n", " transparent_pixels = image.getchannel(\"A\").histogram()[0]\n", " total_pixels = image.width * image.height\n", " transparent_percentage = 100 * transparent_pixels / total_pixels\n", "\n", " if transparent_pixels == 0:\n", " raise ValueError(f\"{filename}.png has no fully transparent pixels.\")\n", "\n", " print(\n", " f\"{filename}.png: {image.width}x{image.height}, \"\n", " f\"{transparent_percentage:.2f}% fully transparent\"\n", " )\n" ] }, { "cell_type": "markdown", "id": "178253af", "metadata": {}, "source": [ "### 2.5 Build a branded PowerPoint slide with Codex\n", "\n", "Give Codex the two transparent chart PNGs, their mock source data, and the required slide theme. Ask it to preserve the alpha channels and use the slide's native background rather than adding white rectangles or decorative background shapes.\n", "\n", "Run the following cell and paste its output into Codex alongside the chart image files.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "5e5be614", "metadata": {}, "outputs": [], "source": [ "presentation_prompt = f\"\"\"\n", "Create one editable 16:9 PowerPoint slide for a fictional NORTHSTAR CLOUD\n", "FY26 Q4 board review using these existing transparent PNG charts:\n", "\n", "- images/transparent-image-assets/quarterly-revenue-growth.png\n", "- images/transparent-image-assets/regional-pipeline-mix.png\n", "\n", "Mock quarterly revenue, in USD millions: {quarterly_revenue}\n", "Mock regional pipeline mix, in percent: {regional_pipeline}\n", "Q1-to-Q4 revenue growth: {revenue_growth:.0%}\n", "\n", "Use a subtle dark navy-to-teal gradient as the slide's native background.\n", "Add the headline \"Growth is accelerating across every region.\"\n", "Add the subheadline \"Revenue climbed 86% over four quarters while pipeline\n", "stayed globally diversified.\"\n", "\n", "Place the quarterly revenue chart on the left and the regional pipeline chart\n", "on the right. Add a heading and short data description above each chart.\n", "Preserve each PNG's real alpha channel so the gradient remains visible behind\n", "both charts. Do not add white image frames, background panels, decorative\n", "shapes, or a separate background-removal step.\n", "\n", "Keep the slide clear, polished, and consistent with an enterprise board-deck\n", "template. Add the fictional company name, reporting period, confidentiality\n", "notice, and page number as editable PowerPoint text.\n", "\"\"\".strip()\n", "\n", "print(presentation_prompt)\n" ] }, { "cell_type": "markdown", "id": "d82d1497", "metadata": {}, "source": [ "### 2.6 View the finished enterprise slide\n", "\n", "PowerPoint files are not rendered directly in notebook output, so the image below shows the completed single-slide presentation. Both generated charts remain separate PNG assets in the underlying PowerPoint file.\n", "\n", "![Enterprise board-review slide with transparent quarterly revenue and regional pipeline charts placed directly on a subtle navy-to-teal gradient background](images/transparent-image-assets/enterprise-chart-slide.png)\n", "\n", "The gradient remains visible behind the bars, through the center of the doughnut chart, and around each label because the charts contain genuine alpha channels. This lets teams add generated visual assets to a required enterprise presentation theme without introducing distracting white boxes.\n" ] }, { "cell_type": "markdown", "id": "d3513a01", "metadata": {}, "source": [ "## Use case 3: Design-template assets\n", "\n", "Design platforms need reusable app icons, stickers, and decorative elements that work across many layouts. Generating these elements with transparent backgrounds lets users drop the same assets into any template without masking, cutting out, or repainting a background.\n", "\n", "### 3.1 Generate transparent design elements" ] }, { "cell_type": "code", "execution_count": null, "id": "d3513a02", "metadata": {}, "outputs": [], "source": [ "design_prompts = {\n", " \"design-app-icon\": (\n", " \"Create one premium rounded-square app icon with an abstract \"\n", " \"folded paper bird in cobalt blue, lavender, and peach. Keep \"\n", " \"everything outside the rounded icon tile transparent. No text, \"\n", " \"watermark, shadows, or background.\"\n", " ),\n", " \"design-sticker\": (\n", " \"Create one illustrated strawberry character sticker with rich \"\n", " \"coral-red fruit, sage-green leaves, and a close-fitting cream \"\n", " \"die-cut border. Keep everything outside the sticker border \"\n", " \"transparent. No text, watermark, shadows, or background.\"\n", " ),\n", " \"design-decoration\": (\n", " \"Create one delicate editorial botanical sprig with fine \"\n", " \"dark-sage branches, muted green leaves, and small coral berries. \"\n", " \"Keep all space around and between the thin branches and leaves \"\n", " \"transparent. No text, shadows, or background.\"\n", " ),\n", "}\n", "\n", "generate_design_assets = True\n", "\n", "if generate_design_assets:\n", " for filename, prompt in design_prompts.items():\n", " result = client.images.generate(\n", " model=IMAGE_MODEL,\n", " prompt=prompt,\n", " background=\"transparent\",\n", " size=\"1024x1024\",\n", " quality=\"high\",\n", " output_format=\"png\",\n", " )\n", "\n", " image_bytes = base64.b64decode(result.data[0].b64_json)\n", " (asset_dir / f\"{filename}.png\").write_bytes(image_bytes)" ] }, { "cell_type": "markdown", "id": "d3513a03", "metadata": {}, "source": [ "### 3.2 Place the assets on a simple website\n", "\n", "Each asset is an independent transparent PNG, ready to move, resize, or reuse on another template.\n", "\n", "| App icon | Transparent sticker | Decorative element |\n", "| --- | --- | --- |\n", "| ![Transparent rounded app icon with an abstract folded paper bird](images/transparent-image-assets/design-app-icon.png) | ![Transparent strawberry character sticker with a close-fitting die-cut border](images/transparent-image-assets/design-sticker.png) | ![Transparent botanical decoration with fine branches and separate leaves](images/transparent-image-assets/design-decoration.png) |\n", "\n", "The sample webpage combines the three assets on a colored template and lets visitors switch the background while keeping the same PNGs in place.\n", "\n", "![Simple design-template website showing a transparent app icon, strawberry sticker, and botanical decoration reused on a colored canvas](images/transparent-image-assets/design-template-studio.png)" ] }, { "cell_type": "markdown", "id": "a9914b01", "metadata": {}, "source": [ "## Use case 4: Print-on-demand merchandise\n", "\n", "Merchandise platforms can generate one print-ready transparent design and place it on different products without removing a white rectangle for every garment color. A single artwork can become a T-shirt, sweatshirt, or another item in a seller's catalog.\n", "\n", "### 4.1 Generate a reusable print design and blank garments" ] }, { "cell_type": "code", "execution_count": null, "id": "a9914b02", "metadata": {}, "outputs": [], "source": [ "merchandise_prompts = {\n", " \"merchandise-design\": (\n", " \"Create one premium outdoors-inspired apparel illustration with \"\n", " \"an amber setting sun, slate-blue mountains, evergreen pine trees, \"\n", " \"a pale turquoise river, and small coral wildflowers. Arrange the \"\n", " \"elements into an organic compact circular composition with subtle \"\n", " \"screen-print texture. Keep the surrounding area and open spaces \"\n", " \"between the graphic elements transparent. No text, bounding \"\n", " \"badge, white rectangle, garment, or background.\"\n", " ),\n", " \"merchandise-blank-tshirt\": (\n", " \"Create one photorealistic premium unisex ivory crew-neck T-shirt \"\n", " \"shown completely flat, front-facing, and centered. Leave the \"\n", " \"chest completely blank for a print design and keep everything \"\n", " \"outside the garment silhouette transparent. No person, hanger, \"\n", " \"mannequin, logos, graphics, shadows, or background.\"\n", " ),\n", " \"merchandise-blank-sweatshirt\": (\n", " \"Create one photorealistic premium forest-green crew-neck \"\n", " \"sweatshirt shown completely flat, front-facing, and centered. \"\n", " \"Leave the chest completely blank for a print design and keep \"\n", " \"everything outside the garment silhouette transparent. No \"\n", " \"person, hanger, mannequin, logos, graphics, shadows, or background.\"\n", " ),\n", "}\n", "\n", "generate_merchandise_assets = True\n", "\n", "if generate_merchandise_assets:\n", " for filename, prompt in merchandise_prompts.items():\n", " result = client.images.generate(\n", " model=IMAGE_MODEL,\n", " prompt=prompt,\n", " background=\"transparent\",\n", " size=\"1024x1024\",\n", " quality=\"high\",\n", " output_format=\"png\",\n", " )\n", "\n", " image_bytes = base64.b64decode(result.data[0].b64_json)\n", " (asset_dir / f\"{filename}.png\").write_bytes(image_bytes)" ] }, { "cell_type": "markdown", "id": "a9914b03", "metadata": {}, "source": [ "### 4.2 Apply one design to multiple products\n", "\n", "The print artwork and both blank garments are separate transparent images. Keeping them separate means a seller can reuse the design across garment types, product colors, and future catalog layouts.\n", "\n", "| Reusable print design | Blank ivory T-shirt | Blank forest-green sweatshirt |\n", "| --- | --- | --- |\n", "| ![Transparent outdoor apparel illustration with mountains, pine trees, and a setting sun](images/transparent-image-assets/merchandise-design.png) | ![Transparent product photograph of a blank ivory crew-neck T-shirt](images/transparent-image-assets/merchandise-blank-tshirt.png) | ![Transparent product photograph of a blank forest-green crew-neck sweatshirt](images/transparent-image-assets/merchandise-blank-sweatshirt.png) |\n", "\n", "Use Pillow to trim empty transparent margins, place the same artwork over each garment, and create a simple two-product catalog preview." ] }, { "cell_type": "code", "execution_count": null, "id": "a9914b04", "metadata": {}, "outputs": [], "source": [ "from PIL import ImageDraw, ImageFont\n", "\n", "\n", "def visible_region(image):\n", " # Remove fully transparent padding without changing visible pixels.\n", " bounds = image.getchannel(\"A\").getbbox()\n", " if bounds is None:\n", " raise ValueError(\"Expected a transparent PNG with visible artwork.\")\n", " return image.crop(bounds)\n", "\n", "\n", "canvas = Image.new(\"RGBA\", (1600, 1020), \"#f7f5f0\")\n", "draw = ImageDraw.Draw(canvas)\n", "\n", "heading_font = ImageFont.load_default(size=57)\n", "body_font = ImageFont.load_default(size=21)\n", "label_font = ImageFont.load_default(size=25)\n", "small_font = ImageFont.load_default(size=17)\n", "\n", "draw.text((86, 70), \"One design, ready to wear.\", font=heading_font, fill=\"#202a27\")\n", "draw.text(\n", " (89, 151),\n", " \"One transparent artwork. Two products. No background removal.\",\n", " font=body_font,\n", " fill=\"#68726d\",\n", ")\n", "\n", "with Image.open(asset_dir / \"merchandise-design.png\") as image:\n", " print_design = visible_region(image.convert(\"RGBA\"))\n", "\n", "garments = [\n", " (\"merchandise-blank-tshirt\", \"Everyday T-shirt\", \"Natural cotton\"),\n", " (\"merchandise-blank-sweatshirt\", \"Essential sweatshirt\", \"Forest green\"),\n", "]\n", "\n", "for index, (filename, title, color) in enumerate(garments):\n", " card_x = 86 + index * 741\n", " card_y = 221\n", " card_width = 690\n", " card_height = 691\n", "\n", " draw.rounded_rectangle(\n", " (card_x, card_y, card_x + card_width, card_y + card_height),\n", " radius=28,\n", " fill=\"#ffffff\",\n", " )\n", "\n", " with Image.open(asset_dir / f\"{filename}.png\") as image:\n", " garment = visible_region(image.convert(\"RGBA\"))\n", "\n", " garment.thumbnail((610, 505), Image.Resampling.LANCZOS)\n", " garment_x = card_x + (card_width - garment.width) // 2\n", " garment_y = card_y + 55 + (505 - garment.height) // 2\n", "\n", " artwork = print_design.copy()\n", " artwork.thumbnail(\n", " (round(garment.width * 0.32), round(garment.height * 0.32)),\n", " Image.Resampling.LANCZOS,\n", " )\n", "\n", " chest_x = (garment.width - artwork.width) // 2\n", " chest_y = round(garment.height * 0.28)\n", " garment.alpha_composite(artwork, dest=(chest_x, chest_y))\n", " canvas.alpha_composite(garment, dest=(garment_x, garment_y))\n", "\n", " draw.text((card_x + 41, card_y + 578), title, font=label_font, fill=\"#202a27\")\n", " draw.text((card_x + 41, card_y + 620), color, font=small_font, fill=\"#68726d\")\n", "\n", "output_path = asset_dir / \"merchandise-print-mockups.png\"\n", "canvas.convert(\"RGB\").save(output_path, optimize=True)\n", "print(f\"Saved merchandise preview to {output_path}\")" ] }, { "cell_type": "markdown", "id": "a9914b05", "metadata": {}, "source": [ "The same transparent design blends naturally into both garment colors while the blank products remain available for other designs.\n", "\n", "![Print-on-demand catalog showing the same transparent outdoor illustration printed on an ivory T-shirt and a forest-green sweatshirt](images/transparent-image-assets/merchandise-print-mockups.png)" ] }, { "cell_type": "markdown", "id": "7e8a5d13", "metadata": {}, "source": [ "## Evaluate the generated assets\n", "\n", "Collect human feedback on transparency, edge quality, brand fit, and usefulness across representative campaigns, slides, design templates, and merchandise mockups. Use a vision-capable language model to evaluate the same assets against a clear rubric, flagging opaque backgrounds, clipped details, poor garment placement, and chart labels that do not match the source data." ] }, { "cell_type": "markdown", "id": "4c2f9b61", "metadata": {}, "source": [ "## Conclusion\n", "\n", "Transparent PNG assets let teams reuse generated images across seasonal campaigns, branded presentations, design templates, and merchandise catalogs without manual background removal. Pairing these workflows with human and vision-model evaluations helps keep creative output consistent as usage grows." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "file_extension": ".py", "mimetype": "text/x-python", "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }