PHPackages                             antonlukin/poster-editor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. antonlukin/poster-editor

ActiveLibrary[Image &amp; Media](/categories/media)

antonlukin/poster-editor
========================

Wrapper for PHP's GD Library for easy image manipulation

6.0(1y ago)20303—0%2[1 PRs](https://github.com/antonlukin/poster-editor/pulls)MITPHPPHP &gt;=7.3.0CI passing

Since Apr 15Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/antonlukin/poster-editor)[ Packagist](https://packagist.org/packages/antonlukin/poster-editor)[ Docs](https://github.com/antonlukin/poster-editor)[ RSS](/packages/antonlukin-poster-editor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (30)Used By (0)

Poster Editor
=============

[](#poster-editor)

This class is an alternative to the package [Intervention Image](https://github.com/Intervention/image) for more flexible work with text on the image. Use it if you need to **fit text** in a given area, automatically **calculate font size** and change **line height**. The text drawing method also knows how to return the actual size of the inscriptions, which will allow, for example, to place blocks under each other.

In addition to flexible work with text, the class provides an Image API similar to the Intervention package. Including smart poster resizing, filters, drawing shapes, and overlaying other images.

If you are not using composer in your work, you may also be interested in the simplicity of the class and the absence of any dependencies. Note that this class supports PHP-GD driver only. You can also easily inherit your class — all methods of the parent can be overridden.

Installation
------------

[](#installation)

The best way to install Poster Editor is quickly and easily with [Composer](http://getcomposer.org/).
However, you can require the class directly without using a loader - this will not affect performance in any way.

`php composer.phar require antonlukin/poster-editor`

Usage
-----

[](#usage)

In case of an error, the class methods return an exception.
Therefore, it is best to call them inside a block `try..catch`.

#### Example

[](#example)

```
// Using composer
require_once __DIR__ . '/vendor/autoload.php';

// Or directly
// require_once __DIR__ . '/PosterEditor.php';

try {
    $image = new PosterEditor\PosterEditor();
    $image->make('images/bridge.jpg')->fit(600, 600);
    $image->show();

} catch(Exception $e) {
    echo $e->getMessage();
}
```

Availible methods
-----------------

[](#availible-methods)

### get

[](#get)

```
$image->get()

```

Get image resource to use raw gd commands.

### set

[](#set)

```
$image->set(instance $resourse)

```

Set image resource after using raw gd commands.

### make

[](#make)

```
$image->make(mixed $data)

```

Make new image instance from file or binary data.

### insert

[](#insert)

```
$image->insert(mixed $data, array $options = array())

```

Paste a given image source over the current image with an optional position. First param can be binary data or path to file or another class instance. Options is an array of x/y relative offset coords from top left corner and opacity from 0 to 100, where 0 is no transparency. By default image will be centered.

### canvas

[](#canvas)

```
$image->canvas(int $width, int $height, array $options = array())

```

Intialise the canvas by width and height. Background color options is in array of color/opacity settings. By default black canvas without opacity.

### show

[](#show)

```
$image->show(string $format = null, int $quality = 90)

```

Sends HTTP response with current image in given format and quality. Format is a file image extension. By default the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). The default value is 90. PNG format is losless and the quality affects only image size and compression speed.

### save

[](#save)

```
$image->save(string $path, int $quality = 90, string $format = null)

```

Save the current state of the image object in filesystem. Define optionally a certain path where the image should be saved. The image type will be defined by file extension. If there is no extension available, the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Optionally you can override this with the format parameter. Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). The default value is 90. PNG format is losless and the quality affects only image size and compression speed.

### destroy

[](#destroy)

```
$image->destroy()

```

Frees memory associated with the current image instance before the PHP script ends. Normally resources are destroyed automatically after the script is finished.

### width

[](#width)

```
$image->width()

```

Returns the height in pixels of the current image.

### height

[](#height)

```
$image->height()

```

Returns the height in pixels of the current image.

### resize

[](#resize)

```
$image->resize(int $width, int $height)

```

Resizes current image based on given width and height. Does not pay attention to the aspect ratio. In order to resize proportionally, use `upsize` and `downsize` methods.

### upsize

[](#upsize)

```
$image->upsize(int $width = null, int $height = null)

```

Upsize image on the largest side. Calculated by ratio for nulled width or height.

### downsize

[](#downsize)

```
$image->downsize(int $width = null, int $height = null)

```

Downsize image on the largest side. Calculated by ratio for nulled width or height.

### crop

[](#crop)

```
$image->crop(int $width, int $height, array $options = array())

```

Cut out a rectangular part of the current image with given width and height. Define optional x,y coordinates to move the top-left corner of the cutout to a certain position.

### fit

[](#fit)

```
$image->fit(int $width, int $height, string $position = 'center')

```

Combine cropping and resizing to format image in a smart way. The method will find the best fitting aspect ratio on the current image automatically, cut it out and resize it to the given dimension. Possible positions `top-left`, `top`, `top-right`, `bottom-left`, `bottom`, `bottom-right`, `right`, `left` and `center` by default.

### line

[](#line)

```
$image->line(int $x1, int $y1, int $x2, int $y2, array $options = array())

```

Draw a line from x,y point 1 to x,y point 2 on current image. Use options param to set color, opacity and width values.

### rectangle

[](#rectangle)

```
$image->rectangle(int $x, int $y, int $width, int $height, array $options = array())

```

Draw a colored rectangle on current image. Use options param to set color, opacity, thickness and outline values.

### ellipse

[](#ellipse)

```
$image->ellipse(int $x, int $y, int $width, int $height, array $options = array())

```

Draw an ellipse. Use options param to set color, opacity and outline values.

### brightness

[](#brightness)

```
$image->brightness(int $level = 0)

```

Change the brightness of the current image by the given level. Use values between -100 for min brightness 0 for no change and +100 for max.

### contrast

[](#contrast)

```
$image->contrast(int $level = 0)

```

Change the contrast of the current image by the given level. Use values between -100 for min contrast 0 for no change and +100 for max.

### grayscale

[](#grayscale)

```
$image->grayscale()

```

Turn an image into a grayscale version.

### blur

[](#blur)

```
$image->blur()

```

Apply a blur image effect.

### invert

[](#invert)

```
$image->invert()

```

Invert colors of an image.

### blackout

[](#blackout)

```
$image->blackout()

```

Draw black opactity rectangle on image.

### rotate

[](#rotate)

```
$image->rotate(int $angle, array $options = array())

```

Rotate image. Set an angle in degrees and optional color of the uncovered zone after the rotation.

### text

[](#text)

```
$image->text(string $text, array $options = array(), array &$boundary = array())

```

Draw text on image. Possible options:

- **x**: X-Coordinate of text box starting point.
- **y**: Y-Coordinate of text box starting point.
- **width**: Width of text box. Calculated from image size for nulled values.
- **height**: Height of text box. Calculated from image size for nulled values.
- **fontsize**: Maximum font size. Will be scaled down if the text doesn't fit box.
- **color**: Color of text. Can be rgb-array or '#ffffff' format.
- **lineheight**: Line height of text.
- **opacity**: Text opacity from 0 to 100. Where 0 is no transparency.
- **horizontal**: Horizontal alignment. Can be left/right/center/justify.
- **vertical**: Vertical alginment. Can be top/center/bottom/justify.
- **fontpath**: Path to .ttf or .otf font file.
- **debug**: Draws text box rectangle if true.

Use boundary to get actual dimensions of the drawn text box. See detailed examples below.

Examples
--------

[](#examples)

### Append downsized image to blackout background

[](#append-downsized-image-to-blackout-background)

```
$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1200, 630, 'bottom')->blackout(50);

$logo = new PosterEditor\PosterEditor();
$logo->make('images/logo.png')->downsize(150, null);

$image->insert($logo, array('x' => 50, 'y' => 50))->show();
```

#### Result

[](#result)

[![append image](tests/references/append.jpg)](tests/references/append.jpg)

### Draw and center multiline text

[](#draw-and-center-multiline-text)

```
$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1200, 630);
$image->grayscale()->brightness(-40);

$image->text(
    'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Lorem ipsum dolor sit amet', // phpcs:ignore
    array(
        'x'          => 100,
        'y'          => 100,
        'width'      => 1000,
        'height'     => 400,
        'horizontal' => 'center',
        'vertical'   => 'center',
        'fontpath'   => 'fonts/opensans.ttf',
        'fontsize'   => 24,
        'lineheight' => 1.75,
        'color'      => '#ffffff',
        'opacity'    => 0,
        'debug'      => true,
    )
);

$image->show('jpg', 70);
```

#### Result

[](#result-1)

[![multiline centered text](tests/references/center.jpg)](tests/references/center.jpg)

### Draw and justify multiline text

[](#draw-and-justify-multiline-text)

```
$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(900, 600);
$image->blackout(70);

$image->text(
    'Lorem ipsum dolor d d 4 g sit amet, consectetur adipiscing et, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex eas commodo consequat sdfsdfl', // phpcs:ignore
    array(
        'x'          => 100,
        'y'          => 100,
        'width'      => 600,
        'height'     => 400,
        'horizontal' => 'justify',
        'vertical'   => 'justify',
        'fontpath'   => 'fonts/opensans.ttf',
        'fontsize'   => 20,
        'lineheight' => 1.5,
        'color'      => '#ffffff',
        'opacity'    => 0,
        'debug'      => true,
    )
);

$image->show('png');
```

#### Result

[](#result-2)

[![multiline justified text](tests/references/justify.png)](tests/references/justify.png)

### Use boundaries to draw one title right after another

[](#use-boundaries-to-draw-one-title-right-after-another)

```
$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->crop(
    900, 600,
    array(
        'x' => '0',
        'y' => '100'
    )
);

$image->grayscale()->brightness(-40);

$image->text(
    'Large title with unknown height. Can be multi-line',
    array(
        'x'          => 50,
        'y'          => 100,
        'width'      => 800,
        'fontpath'   => '/fonts/merriweather.ttf',
        'fontsize'   => 48,
        'lineheight' => 1.5,
        'color'      => '#9999ff',
    ),
    $boundary
);

$image->text(
    'This text appears right after title using smart boundaries',
    array(
        'x'          => 50,
        'y'          => $boundary['y'] + $boundary['height'],
        'width'      => 800,
        'fontpath'   => '/fonts/opensans.ttf',
        'fontsize'   => 20,
        'lineheight' => 1.5,
        'color'      => '#ff9999',
    ),
    $boundary
);

$image->show();
```

#### Result

[](#result-3)

[![boundary](tests/references/boundary.jpg)](tests/references/boundary.jpg)

### Draw shapes

[](#draw-shapes)

```
$image = new PosterEditor\PosterEditor();
$image->make('images/bridge.jpg')->fit(1000, 630, 'bottom');
$image->contrast(5)->brightness(-30)->blur();

$image->rectangle(
    20, 20, 960, 590,
    array(
        'color'   => '#ffffff',
        'outline' => true,
        'width'   => 4,
    )
);

$image->ellipse(
    200, 200, 200, 200,
    array(
        'color'   => '#00ff00',
        'opacity' => 50,
    )
);

$image->ellipse(
    800, 200, 200, 200,
    array(
        'color'   => '#ff0000',
        'opacity' => 50,
    )
);

$image->rectangle(
    480, 280, 80, 140,
    array(
        'color'   => '#0000ff',
    )
);

$image->line(
    200, 500, 800, 500,
    array(
        'color'   => array(255, 255, 0),
        'opacity' => 10,
        'width'   => 4,
    )
);

$image->show('png');
```

#### Result

[](#result-4)

[![shapes result](tests/references/shapes.png)](tests/references/shapes.png)

Contribution
------------

[](#contribution)

All project code is stored on Github. The best way to help the project is to report a bug or add some new functionality. You can also open here an [issue](https://github.com/antonlukin/poster-editor/issues) or send a [pull reguest](https://github.com/antonlukin/poster-editor/pulls).

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance63

Regular maintenance activity

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~58 days

Recently: every ~78 days

Total

25

Last Release

468d ago

Major Versions

2.3 → 3.02021-04-26

3.0 → 4.02021-06-12

4.1 → 5.02021-06-24

5.16 → 6.02025-02-04

PHP version history (2 changes)2.0PHP &gt;=7.1.0

6.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ba1a7e56be4dbfc357bf3e19a99dc080b914265bf924580ca645b6cf9ad1a1d?d=identicon)[antonkukin](/maintainers/antonkukin)

---

Top Contributors

[![antonlukin](https://avatars.githubusercontent.com/u/454185?v=4)](https://github.com/antonlukin "antonlukin (47 commits)")[![cadic](https://avatars.githubusercontent.com/u/288381?v=4)](https://github.com/cadic "cadic (1 commits)")

---

Tags

composerimage-processingimage-textinterventionphpphp-classphp-gdphp-imagephp-libraryposter-editorphpimagegdtext

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/antonlukin-poster-editor/health.svg)

```
[![Health](https://phpackages.com/badges/antonlukin-poster-editor/health.svg)](https://phpackages.com/packages/antonlukin-poster-editor)
```

###  Alternatives

[stefangabos/zebra_image

A single-file, lightweight PHP library designed for efficient image manipulation featuring methods for modifying images and applying filters

141110.4k6](/packages/stefangabos-zebra-image)[nmcteam/image-with-text

Create images with embedded text and advanced typography

14073.5k](/packages/nmcteam-image-with-text)[eskandari/persianrender

PersianRender,Free persian letter conertor for using in php GD, etc.

2515.2k](/packages/eskandari-persianrender)[rathouz/text-image

A simple PHP library to convert text to images.

174.9k1](/packages/rathouz-text-image)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
