Automatic Product Image Generation for Social Media
Every day a marketer spends 20–30 minutes creating one branded image for a new product. Multiply by 100 items — you lose a week. We automate this: the system takes data from the product card (photo, name, price, brand) and generates ready-to-use banners for each social network — Telegram, VK, Instagram, Stories. Result: uniform graphics in seconds, not hours.
How the template generator works
We use the Pillow library (Python) or Sharp (Node.js). Product fields are placed on pre-made templates. Fonts, colors, logo — everything matches the brand book. The generator adapts text to dimensions: if the name is long, the font size is reduced; if the price is with a discount, it's highlighted in yellow.
Example: for an online clothing store, we set up 5 templates for different categories. When a product is added to the CMS, 4 image variants are automatically created — square post, portrait post, story, and Telegram preview. Result: 20 seconds instead of 20 minutes.
from PIL import Image, ImageDraw, ImageFont
import httpx
from io import BytesIO
class ProductBannerGenerator:
TEMPLATES = {
'feed': (1080, 1080), # Instagram/VK post
'story': (1080, 1920), # Instagram/VK Stories
'telegram': (1280, 640), # Telegram preview
}
def generate(self, product: dict, format: str = 'feed') -> bytes:
width, height = self.TEMPLATES[format]
canvas = Image.new('RGB', (width, height), color='#FFFFFF')
draw = ImageDraw.Draw(canvas)
if product.get('image_url'):
product_img = self._load_image(product['image_url'])
product_img = self._fit_image(product_img, (width, int(height * 0.65)))
canvas.paste(product_img, (0, 0))
gradient = self._create_gradient((width, int(height * 0.4)), '#000000', alpha_start=0, alpha_end=180)
canvas.paste(gradient, (0, int(height * 0.6)), mask=gradient)
font_title = ImageFont.truetype('fonts/Inter-Bold.ttf', size=52)
font_price = ImageFont.truetype('fonts/Inter-ExtraBold.ttf', size=72)
font_small = ImageFont.truetype('fonts/Inter-Regular.ttf', size=36)
y_offset = int(height * 0.68)
draw.text((60, y_offset), product['name'], font=font_title, fill='white')
draw.text((60, y_offset + 70), f"{product['price']:,.0f} ₽", font=font_price, fill='#FFD700')
logo = Image.open('assets/logo.png').resize((200, 60))
canvas.paste(logo, (width - 220, 20), mask=logo)
output = BytesIO()
canvas.save(output, 'JPEG', quality=90)
return output.getvalue()
def _load_image(self, url: str) -> Image.Image:
resp = httpx.get(url, timeout=15)
return Image.open(BytesIO(resp.content)).convert('RGBA')
Why template generation is better than AI for mass content
Template approach surpasses AI generation in speed and predictability: it's 10 times faster and doesn't require GPU costs. If you need unique graphics for each product (e.g., for a premium brand), we connect Stable Diffusion via Replicate API. The background is generated for the product category, then text is overlaid. This is more expensive but provides variety.
import replicate
def generate_ai_background(product_name: str, category: str) -> str:
output = replicate.run(
"stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
input={
"prompt": f"minimalist product photography background for {category}, clean white studio, soft shadows, high-end commercial photo",
"negative_prompt": "text, watermark, ugly, blurry",
"width": 1080,
"height": 1080,
}
)
return output[0]
Which formats and sizes are supported
All popular formats are pre-configured. The system outputs ready files in one package.
| Platform | Post | Stories |
|---|---|---|
| 1080×1080, 1080×1350 | 1080×1920 | |
| VK | 1080×1080 | 1080×1920 |
| Telegram channel | 1280×640 | — |
Comparison of approaches: template vs AI
| Parameter | Template | AI generation |
|---|---|---|
| Speed | 1–2 seconds per image | 10–30 seconds including queue |
| Predictability | 100% identical result | Possible artifacts |
| Cost | CPU only | GPU or API (Replicate, Midjourney) |
| Uniqueness | Limited by templates | Each image is new |
How to avoid common mistakes during automation
- Incorrect text clipping: if the product name is longer than 200 characters, text may overflow boundaries. Solution: configure automatic wrapping and font size reduction.
- Ignoring formats: each social network needs its own proportions. The universal 1080×1080 size is not suitable for all — Telegram preview requires 1280×640.
- Lack of fallback images: if the product has no photo, the generator should use a placeholder with a branded background, otherwise the banner will be empty.
What's included in the work
Turnkey image generator: source code, template setup instructions, repository access, 1 month of support. Additionally, we provide a set of ready templates for typical product categories and instructions for extending them. Pillow documentation recommends using ImageFont.truetype for consistent text rendering across platforms. Integration with any CMS (WordPress, Laravel, Django). We'll estimate the project in 1 day.
How to integrate the generator with the website
- Analytics — examine your CMS, product types, current graphics.
- Template design — create layouts according to the brand book (3–5 variants).
- Generator development — write code using Pillow, configure the API.
- Integration — connect to your website or admin panel.
- Testing — check on 50+ products, adjust.
- Deployment and documentation — provide access, instructions for adding templates.
Timeline
Basic template-based generator with 3 formats — from 4 to 6 business days. With AI background generation — from 7 to 9 days. If a brand book and font set are ready, the timeline reduces by 1–2 days. If no brand book exists, we'll develop templates based on your website or specified color scheme. The exact estimate is provided after analyzing your products and format requirements.
Time savings from automation reach up to 20 hours per week, which at an average designer rate gives budget savings of up to 120,000 ₽ per month. The investment pays off in 2–3 months. We guarantee: over 10 years of development experience, over 50 successful content automation projects. Contact us for a consultation and examples of generation for your niche. Order content automation — reduce publication time by 10 times.







