mjohann / theme2cover
Theme2Cover is a PHP library that generates 1920x1080 cover images from a simple text theme. It automatically creates a visual composition with random colors, geometric elements, decorative details, and typography, returning the generated image as a Base64-encoded JPEG.
Requires
- php: ^8.5
- intervention/image: ^4.3
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Theme2Cover is a PHP library that generates 1920Γ1080 cover images from a simple text theme. It automatically creates a visual composition with random colors, geometric elements, decorative details, and typography, returning the generated image as a Base64-encoded JPEG.
π¦ Installation
Install via Packagist/Composer:
composer require mjohann/theme2cover
βοΈ Requirements
- PHP 8.5 or higher
- Intervention Image
- GD extension
π Features
Theme2Cover provides an automated way to generate visual covers from text, without requiring a predefined image or a manual design process.
The currently supported features include:
π¨ Random Visual Composition
Each generated cover uses a randomly selected visual composition.
The library currently provides six different composition styles:
- Large circles
- Small circles
- Grid
- Bars
- Mixed composition
- Abstract composition
The style is selected randomly every time a cover is generated.
π Random Color Palette
The color palette is generated mathematically using the HSL color model.
Each cover receives:
- Background color
- Surface color
- Primary color
- Secondary color
- Accent color
The colors are generated dynamically, so repeated executions can produce different visual results.
βοΈ Automatic Typography
The theme is rendered using the bundled Montserrat Bold font.
The library automatically adjusts the font size according to the length of the theme:
- Up to 25 characters β
92px - Up to 45 characters β
82px - Up to 70 characters β
70px - More than 70 characters β
62px
The text also supports automatic wrapping with a maximum width of 1100px.
π· Decorative Elements
Generated covers include randomly positioned decorative elements such as:
- Circles
- Rectangles
- Bars
- Dots
- Top accent bar
- Title decoration
- Bottom decorative line
These elements are combined with the generated color palette to create a unique composition.
πΌοΈ Base64 Output
The generated image is encoded as JPEG with quality 92 and returned as a Base64 data URI:
data:image/jpeg;base64,...
This makes the result directly usable in HTML, CSS, APIs, or other applications that support data URIs.
π§ͺ Usage Examples
πΌοΈ Generate a Cover
The main API is the static Theme2Cover::create() method.
It receives the theme as a string and returns the generated cover as a Base64-encoded JPEG.
<?php use MJohann\Packlib\Theme2Cover; require_once "vendor/autoload.php"; $cover = Theme2Cover::create( "Artificial Intelligence" ); echo $cover;
π Display the Generated Cover in HTML
Because the method returns a complete Base64 data URI, the result can be used directly as the src attribute of an HTML image.
<?php use MJohann\Packlib\Theme2Cover; require_once "vendor/autoload.php"; $cover = Theme2Cover::create( "Artificial Intelligence" ); ?> <img src="<?= $cover ?>" alt="Generated cover" />
π¦ Use the Result in an API
The generated Base64 string can also be returned directly from an API.
<?php use MJohann\Packlib\Theme2Cover; require_once "vendor/autoload.php"; $cover = Theme2Cover::create( "PHP Development" ); header( 'Content-Type: application/json' ); echo json_encode([ 'theme' => 'PHP Development', 'cover' => $cover, ]);
π The main implementation is available in
src/Theme2Cover.php.
π² Random Generation
The generated composition is intentionally random.
For each call to:
Theme2Cover::create($tema);
the library randomly determines:
- Color palette
- Visual style
- Number of geometric elements
- Element positions
- Element sizes
- Decorative details
- Font size based on the theme length
Therefore, calling the method multiple times with the same theme can generate different covers.
$cover1 = Theme2Cover::create("Web Development"); $cover2 = Theme2Cover::create("Web Development");
$cover1 and $cover2 may have completely different visual compositions even though the theme is the same.
πΌοΈ Image Specifications
Every generated cover follows the same base specifications:
| Property | Value |
|---|---|
| Width | 1920px |
| Height | 1080px |
| Format | JPEG |
| Quality | 92 |
| Output | Base64 Data URI |
| Font | Montserrat Bold |
| Maximum title width | 1100px |
The resulting image uses a 16:9 aspect ratio, making it suitable for presentations, articles, videos, thumbnails, social media content, and other visual applications.
π§© Composition Styles
1. Large Circles
Generates a composition with a small number of large circles positioned on the right side of the cover.
2. Small Circles
Generates several smaller circles with different sizes and colors.
3. Grid
Creates a collection of randomly positioned rectangles, producing a grid-like visual composition.
4. Bars
Generates horizontal bars with random dimensions and colors.
5. Mixed Composition
Combines large circles, smaller circles, and rectangular elements into a single composition.
6. Abstract Composition
Combines large circles with small decorative points to create a more abstract visual layout.
π Project Structure
theme2cover/
βββ src/
β βββ fonts/
β β βββ Montserrat-Bold.ttf
β βββ Theme2Cover.php
βββ composer.json
βββ composer.lock
βββ .gitignore
βββ LICENSE
βββ README.md
π License
This project is licensed under the MIT License.
π¨βπ» Author
Developed by Matheus Johann AraΓΊjo β Pernambuco, Brazil.