PHPackages                             kus/php-image - 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. kus/php-image

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

kus/php-image
=============

Wrapper for PHP's GD Library for easy image manipulation

16281.7k↓36.7%50[5 issues](https://github.com/kus/php-image/issues)[1 PRs](https://github.com/kus/php-image/pulls)PHP

Since Mar 27Pushed 3y ago17 watchersCompare

[ Source](https://github.com/kus/php-image)[ Packagist](https://packagist.org/packages/kus/php-image)[ RSS](/packages/kus-php-image/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Image
=========

[](#php-image)

What does it do?
----------------

[](#what-does-it-do)

Wrapper for PHP's GD Library for easy image manipulation to resize, crop and draw images on top of each other preserving transparency, writing text with stroke and transparency and drawing shapes.

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

[](#installation)

Place the PHP file on your server and include it in your script or download via [composer](https://getcomposer.org/) `require: "kus/php-image": "dev-master"`.

Usage
=====

[](#usage)

Example
-------

[](#example)

```
	$bg = './img/benji.jpg';
	$overlay = './img/paw.png';
	$image = new PHPImage();
	$image->setDimensionsFromImage($bg);
	$image->draw($bg);
	$image->draw($overlay, '50%', '75%');
	$image->rectangle(40, 40, 120, 80, array(0, 0, 0), 0.5);
	$image->setFont('./font/arial.ttf');
	$image->setTextColor(array(255, 255, 255));
	$image->setStrokeWidth(1);
	$image->setStrokeColor(array(0, 0, 0));
	$image->text('Hello World!', array('fontSize' => 12, 'x' => 50, 'y' => 50));
	$image->text('This is a big sentence with width 200px', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 300,
		'y' => 0,
		'width' => 200,
		'height' => 50,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->text('This is a big sentence', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 300,
		'y' => 200,
		'width' => 200,
		'height' => 50,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', array('width' => 100, 'fontSize' => 8, 'x' => 50, 'y' => 70));
	$image->rectangle(40, 140, 170, 160, array(0, 0, 0), 0.5);
	$image->textBox('Auto wrap and scale font size to multiline text box width and height bounds. Vestibulum venenatis risus scelerisque enim faucibus, ac pretium massa condimentum. Curabitur faucibus mi at convallis viverra. Integer nec finibus ligula, id hendrerit felis.', array(
		'width' => 150,
		'height' => 140,
		'fontSize' => 16, // Desired starting font size
		'x' => 50,
		'y' => 150
	));
	$image->show();
```

[![Overlay and text](https://camo.githubusercontent.com/d92ae2b54ff2a6c803d755d1073c0ae27b837a73f06565248e23b2f289b0f0a7/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f6f7665726c61792e6a7067 "Overlay and text")](https://camo.githubusercontent.com/d92ae2b54ff2a6c803d755d1073c0ae27b837a73f06565248e23b2f289b0f0a7/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f6f7665726c61792e6a7067)

Chainable
---------

[](#chainable)

```
	(new PHPImage('./img/benji.jpg'))->resize(200, 200, 'C', true)->show();
```

Batch resize with optional crop and upscale
-------------------------------------------

[](#batch-resize-with-optional-crop-and-upscale)

```
	$image = new PHPImage('./img/benji.jpg');
	$image->batchResize('examples/thumb_%dx%d.jpg', array(
		array(400, 400, true, true),
		array(200, 400, true, true),
		array(400, 200, true, true),
		array(100, 100, true, true),
	));
	$image->resize(100, 100, true, true)->show();
```

[![400x400](https://camo.githubusercontent.com/737139c87bedc36b585c66173fc208a41681364fc553d0639818d821594c6c05/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f343030783430302e6a7067 "400x400")](https://camo.githubusercontent.com/737139c87bedc36b585c66173fc208a41681364fc553d0639818d821594c6c05/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f343030783430302e6a7067)[![400x200](https://camo.githubusercontent.com/f1f163929e10d2505426bb62687f33701e245724ebf6e54085a71dfdd324b968/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f343030783230302e6a7067 "400x200")](https://camo.githubusercontent.com/f1f163929e10d2505426bb62687f33701e245724ebf6e54085a71dfdd324b968/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f343030783230302e6a7067)[![200x400](https://camo.githubusercontent.com/b5ab8856d61c9f94e3ae3f5fc66e0412c882d0379d40dea3b98c7fa54306444c/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f323030783430302e6a7067 "200x400")](https://camo.githubusercontent.com/b5ab8856d61c9f94e3ae3f5fc66e0412c882d0379d40dea3b98c7fa54306444c/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f323030783430302e6a7067)[![100x100](https://camo.githubusercontent.com/8b86c3372581ae495f6ce79f456457951a0a05d5440da49e8e751ba9f20d3fc2/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f313030783130302e6a7067 "100x100")](https://camo.githubusercontent.com/8b86c3372581ae495f6ce79f456457951a0a05d5440da49e8e751ba9f20d3fc2/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f7468756d625f313030783130302e6a7067)

Multiline text box with auto wrap and auto font scale to fit bounds
-------------------------------------------------------------------

[](#multiline-text-box-with-auto-wrap-and-auto-font-scale-to-fit-bounds)

```
	$image = new PHPImage(400, 400);
	$image->rectangle(0, 0, 100, 200, array(0, 0, 0), 0.5);
	$image->setFont('./font/arial.ttf');
	$image->setTextColor(array(255, 255, 255));
	$image->setStrokeWidth(1);
	$image->setStrokeColor(array(0, 0, 0));
	$image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam molestie tortor quam, at congue nibh imperdiet dapibus.', array(
		'width' => 100,
		'height' => 100,
		'fontSize' => 16, // Desired starting font size
		'x' => 50,
		'y' => 200
	));
	$image->show();
```

[![Multiline auto fit text](https://camo.githubusercontent.com/f317474ca5458ef8f1ef2e0fbe1c28bddc56ab8b5789d89693bbf41e5c57c182/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f746578742e6a7067 "Multiline auto fit text")](https://camo.githubusercontent.com/f317474ca5458ef8f1ef2e0fbe1c28bddc56ab8b5789d89693bbf41e5c57c182/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f746578742e6a7067)

[![Multiline text alignment](https://camo.githubusercontent.com/ecdb192e7fac655878edda3dbdc10a8e11972716054df635bed3a23676fa39e4/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f63656e7465722e6a7067 "Multiline text alignment")](https://camo.githubusercontent.com/ecdb192e7fac655878edda3dbdc10a8e11972716054df635bed3a23676fa39e4/68747470733a2f2f7261772e6769746875622e636f6d2f6b75732f7068702d696d6167652f6d61737465722f746573742f6578616d706c65732f63656e7465722e6a7067)

Text box auto fit text (variable font size)
-------------------------------------------

[](#text-box-auto-fit-text-variable-font-size)

```
	$image = new PHPImage(400, 400);
    $image->setFont('./font/arial.ttf');
    $image->setTextColor(array(255, 255, 255));
    $image->text('This is a big sentence', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 0,
		'y' => 0,
		'width' => 400,
		'height' => 200,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->text('BIG', array(
		'fontSize' => 120, // Desired starting font size
		'x' => 0,
		'y' => 200,
		'width' => 400,
		'height' => 200,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
    $image->show();
```

Copyright
---------

[](#copyright)

Copyright (c) 2015 Blake Kus [blakek.us](http://blakek.us)

This plugin is dual licenced under MIT and GPL Version 2 licences.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 57.1% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/911c57ebcf0dffeb3693b127c0017997475581dc06e0426380af771633b9cda8?d=identicon)[Kus](/maintainers/Kus)

---

Top Contributors

[![kus](https://avatars.githubusercontent.com/u/571523?v=4)](https://github.com/kus "kus (12 commits)")[![aidabeorn](https://avatars.githubusercontent.com/u/219796?v=4)](https://github.com/aidabeorn "aidabeorn (4 commits)")[![Svish](https://avatars.githubusercontent.com/u/142162?v=4)](https://github.com/Svish "Svish (4 commits)")[![bigfoot90](https://avatars.githubusercontent.com/u/4598274?v=4)](https://github.com/bigfoot90 "bigfoot90 (1 commits)")

### Embed Badge

![Health badge](/badges/kus-php-image/health.svg)

```
[![Health](https://phpackages.com/badges/kus-php-image/health.svg)](https://phpackages.com/packages/kus-php-image)
```

###  Alternatives

[goat1000/svggraph

Generates SVG graphs

135911.1k3](/packages/goat1000-svggraph)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

16653.6k2](/packages/gravatarphp-gravatar)[rsoury/wp-imgix

Rewrites WordPress image URLs to use ImgIX

167.2k](/packages/rsoury-wp-imgix)

PHPackages © 2026

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