PicTex v1.0 is here: a declarative layout engine for creating images in Python

Hey r/Python,

A few weeks ago, I posted about my personal project, PicTex, a library for making stylized text images. I’m really happy for all the feedback and suggestions I received.

It was a huge motivator and inspired me to take the project to the next level. I realized the core idea of a simple, declarative API could be applied to more than just a single block of text. So, PicTex has evolved. It’s no longer just a « text-styler »; it’s now a declarative UI-to-image layout engine.

You can still do simple, beautiful text banners easily:

« `python from pictex import Canvas, Shadow, LinearGradient

1. Create a style template using the fluent API

canvas = ( Canvas() .font_family(« Poppins-Bold.ttf ») .font_size(60) .color(« white ») .padding(20) .background_color(LinearGradient([« #2C3E50 », « #FD746C »])) .border_radius(10) .text_shadows(Shadow(offset=(2, 2), blur_radius=3, color= »black »)) )

2. Render some text using the template

image = canvas.render(« Hello, World! 🎨✨ »)

3. Save or show the result

image.save(« hello.png ») « ` Result: https://imgur.com/a/Wp5TgGt

But now you can compose different components together. Instead of just rendering text, you can now build a whole tree of Row, Column, Text, and Image nodes.

Here’s a card example:

« `python from pictex import *

1. Create the individual content builders

avatar = ( Image(« avatar.jpg ») .size(60, 60) .border_radius(‘50%’) )

user_info = Column( Text(« Alex Doe »).font_size(20).font_weight(700), Text(« @alexdoe »).color(« #657786 ») ).gap(4)

2. Compose the builders in a layout container

user_banner = Row( avatar, user_info ).gap(15).vertical_align(‘center’)

3. Create a Canvas and render the final composition

canvas = Canvas().padding(20).background_color(« #F5F8FA ») image = canvas.render(user_banner)

4. Save the result

image.save(« user_banner.png ») « ` Result: https://imgur.com/a/RcEc12W

The library automatically handles all the layout, sizing, and positioning based on the Row/Column structure.

What My Project Does

PicTex is now a declarative framework for generating static images from a component tree. It allows you to:

Compose Complex Layouts: Build UIs by nesting Row, Column, Text, and Image nodes. Automatic Layout: It uses a Flexbox-like model to automatically handle positioning and sizing. Set gap, distribution, and alignment. Universal Styling: Apply backgrounds, padding, borders, shadows, and border-radius to any component, not just the text. Advanced Typography: All the original features are still there: custom fonts, font fallbacks for emojis, gradients, outlines, etc. Native Python: It’s all done within Python using Skia, with no need for external dependencies like a web browser or HTML renderer.

Target Audience

The target audience has grown quite a bit! It’s for anyone who needs to generate structured, data-driven images in Python.

Generating social media profile cards, quote images, or event banners. Creating dynamic Open Graph images for websites. Building custom info-graphics or report components. Developers familiar with declarative UI frameworks who want a similar experience for generating static images in Python.

It’s still a personal project at heart, but it’s becoming a much more capable and general-purpose tool.

Comparison

The evolution of the library introduces a new set of comparisons:

vs. Pillow/OpenCV: Pillow is a drawing canvas; PicTex is a layout engine. With PicTex, you describe the structure of your UI and let the library figure out the coordinates. Doing the profile card example in Pillow would require dozens of manual calculations for every single element’s position and size.

vs. HTML/CSS-to-Image libraries: These are powerful but come with a major dependency: a full web browser engine (like WebKit or Chrome). This can be heavy, slow, and a pain to set up in production environments. PicTex is a native Python solution. It’s a single, self-contained pip install with no external binaries to manage. This makes it much lighter and easier to deploy.

I’m so grateful for the initial encouragement. It genuinely inspired me to push this project further. I’d love to hear what you think of the new direction!

There are probably still some rough edges, so all feedback is welcome.

GitHub Repo: https://github.com/francozanardi/pictex PyPI Page: https://pypi.org/project/pictex/ (The new version is up!)

submitted by /u/_unknownProtocol to r/Python
[link] [comments]


Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *