PHPackages                             tiross/imagecraft - 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. tiross/imagecraft

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

tiross/imagecraft
=================

A reliable and extensible PHP image manipulation library

v1.0.5(10y ago)011MITPHPPHP &gt;=5.4.0

Since Oct 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Tiross/imagecraft)[ Packagist](https://packagist.org/packages/tiross/imagecraft)[ Docs](https://github.com/coldume/imagecraft)[ RSS](/packages/tiross-imagecraft/feed)WikiDiscussions develop Synced 3d ago

READMEChangelogDependencies (4)Versions (8)Used By (0)

Imagecraft
==========

[](#imagecraft)

[![Build Status](https://camo.githubusercontent.com/28976256ad2c02616cb4a8b28012e9486b9831126fb536828b77b9e0a81f311f/68747470733a2f2f7472617669732d63692e6f72672f636f6c64756d652f696d61676563726166742e737667)](https://travis-ci.org/coldume/imagecraft)

Imagecraft is a reliable and extensible PHP image manipulation library. It can edit and compose images in multiple layers and supports watermark, resize and text. Furthermore, it keeps GIF animation, optimizes memory usage, catches memory exhausted error, and gives an user-friendly/translated feedback.

Imagecraft is intended to be an image abstraction &amp; manipulation layer, which offers a PDO-like API. It currently supports GD extension, and will support ImageMagick in version 2.0. If you have any suggestions, comments or feedback, let me know. Thanks.

Requirement
-----------

[](#requirement)

- PHP &gt;= 5.6.0
- PHP GD extension

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

[](#installation)

[Composer](https://getcomposer.org) is the recommended way to install Imagecraft, simply add a dependency to your project's composer.json file:

```
{
    "require": {
        "coldume/imagecraft": "~1.0"
    }
}
```

Or, you can install from an archive file: [imagecraft\_1.0.4.zip](https://docs.google.com/uc?id=0B5ruhRHby-kbQlVzcHN3TFhNNzQ&export=download)

Usage
-----

[](#usage)

### Provide the User with a Hint on What He Needs to Upload

[](#provide-the-user-with-a-hint-on-what-he-needs-to-upload)

```
use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd'];
$builder = new ImageBuilder($options);
$context = $builder->about();
if (!$context->isEngineSupported()) {
    echo 'Sorry, image processing service is currently not available.'.PHP_EOL;
} else {
    $formats = $context->getSupportedImageFormatsToString();
    echo 'Make sure that you\'re using one of the following image formats: '.$formats.'.'.PHP_EOL;
    $formats = $context->getSupportedFontFormatsToString();
    echo 'We accept the following font formats: '.$formats.'.'.PHP_EOL;
}
```

### Build an Image in Fluent Pattern

[](#build-an-image-in-fluent-pattern)

1. Client uploads an [image](https://cloud.githubusercontent.com/assets/5236124/9806426/4b49fe20-5812-11e5-8a44-bdbdfff2787a.gif) from URL.
2. Server performs resize and [watermark](https://cloud.githubusercontent.com/assets/5236124/9806423/4b465d4c-5812-11e5-8dc9-f0f7257e7cda.png) operations.
3. Server returns a message in English if an error occured, such as data size exceeds allowable limit (2MB), timeout expired (20s), file not found, etc.

```
use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd', 'locale' => 'en'];
$builder = new ImageBuilder($options);
$image = $builder
    ->addBackgroundLayer()
        ->http('www.imagecraft.cc/web/images/pikachu.gif', 2048, 20)
        ->resize(400, 400, 'shrink')
        ->done()
    ->addImageLayer()
        ->filename(__DIR__.'/pikachu_what_to_do_logo_by_mnrart-d5h998b.png')
        ->move(-20, -20, 'bottom_right')
        ->done()
    ->save()
;
if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
} else {
    echo $image->getMessage().PHP_EOL;
}
```

[![Fluent Pattern Output](https://cloud.githubusercontent.com/assets/5236124/9806425/4b49d224-5812-11e5-92d6-2f3514ebd660.gif)](https://cloud.githubusercontent.com/assets/5236124/9806425/4b49d224-5812-11e5-92d6-2f3514ebd660.gif)

### Build an Image in Classic Pattern

[](#build-an-image-in-classic-pattern)

1. Client uploads an [image](https://cloud.githubusercontent.com/assets/5236124/9806422/4b4582dc-5812-11e5-9e85-8974e48dfdfd.gif) directly.
2. Server performs thumbnail and [text](https://drive.google.com/open?id=0B5ruhRHby-kbQmxKVDVEaEc3Zkk) operations.
3. Server returns a message in traditional Chinese if an error occured.

```
use Imagecraft\ImageBuilder;

$options = ['engine' => 'php_gd', 'locale' => 'zh_TW'];
$builder = new ImageBuilder($options);

$layer = $builder->addBackgroundLayer();
$layer->filename(__DIR__.'/yotsuba_koiwai.gif');
$layer->resize(150, 150, 'fill_crop');

$layer = $builder->addTextLayer();
$layer->font(__DIR__.'/minecraftia.ttf', 12, '#FFF');
$layer->label(date('F j, Y, g:i a'));
$layer->move(-10, -10, 'bottom_right');

$image = $builder->save();
if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
} else {
    echo $image->getMessage().PHP_EOL;
}
```

[![Classic Pattern Output](https://cloud.githubusercontent.com/assets/5236124/9806424/4b485480-5812-11e5-818c-a2aa8b2c2c9d.gif)](https://cloud.githubusercontent.com/assets/5236124/9806424/4b485480-5812-11e5-818c-a2aa8b2c2c9d.gif)

### When Debugging is Easier than Expected

[](#when-debugging-is-easier-than-expected)

```
use Imagecraft\ImageBuilder;

// Build an image

if ($image->isValid()) {
    file_put_contents(__DIR__.'/output.'.$image->getExtension(), $image->getContents());
    print_r($image->getExtras());
} else {
    echo $image->getMessage().PHP_EOL;
    print_r($image->getVerboseMessage());
}
```

Cheat Sheet
-----------

[](#cheat-sheet)

### Options

[](#options)

NameDefaultAvailableDescription`engine``php_gd``php_gd`image library to be used`cache_dir``n/a``n/a`project-specific cache directory`debug``true``true, false`debug mode of your project`locale``en``en, zh_TW, ..`error message language`jpeg_quality``100``[0, 100]`quality of the JPEG image`png_compression``100``[0, 100]`compression level of the PNG image`memory_limit``-10``[-∞, ∞]`maximum memory to use in MB`gif_animation``true``true, false`whether to maintain the GIF animation`output_format``default``jpeg, png, ..`output image format### Layers

[](#layers)

MethodCompatible`http(`[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The URL begins with http://, https:// or nothing.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$url, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The data limit in KB. If set to -1, no data limit is imposed.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$dataLimit = -1, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The timeout in second. If set to -1, no timeout is imposed")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$timeout = -1)``BackgroundLayer`, `ImageLayer``filename($filename)``BackgroundLayer`, `ImageLayer``contents($contents)``BackgroundLayer`, `ImageLayer``resize($width, $height, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The resize option. Predefined values: shrink, fill_crop.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$option = 'shrink')``BackgroundLayer`, `ImageLayer``move($x, $y, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The move gravity. Predefined values: top_left, top_center, top_right, center_left, center, center_right, bottom_left, bottom_center, bottom_right.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$gravity = 'center')``ImageLayer`, `TextLayer``font($filename, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The font size to use in points.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$size = 12, $color = '#FFF')``TextLayer``label($label)``TextLayer``angle(`[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The angle in degrees.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$angle)``TextLayer``lineSpacing($lineSpacing)``TextLayer``box(array `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The four paddings of the box.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$paddings, `[![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "The color of the box. null means transparent.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)`$color = null)``TextLayer`- Letting your mouse hover over [![Hint](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67 "Yes, you got it.")](https://camo.githubusercontent.com/0230951626d2e021dd8554f1795b5326a0a74ad2ba589024671f3082e41f30e4/687474703a2f2f7777772e696d61676563726166742e63632f7765622f696d616765732f746f6f6c7469702e706e67)should cause a tooltip to appear.
- Method `http()`, `filename()` or `contents()` is required for `BackgroundLayer`and `ImageLayer`.
- Methods `font()` and `label()` are required for `TextLayer`.

Tips
----

[](#tips)

1. In addition to the default English error message, Imagecraft can be switched to other languages. You can help with existing translations or to add another language. The translation files are located at:

    -
    -

Resources
---------

[](#resources)

- Mike Flickinger (2005) "What's In A GIF".

    .
- David C. Kay (1994) "Graphic File Formats".

    .

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~164 days

Total

4

Last Release

3725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e0e7a7749bc1b1ec61b74552fb665ae81e90d70445c5a459601f5e13ced57d8d?d=identicon)[Tiross](/maintainers/Tiross)

---

Top Contributors

[![coldume](https://avatars.githubusercontent.com/u/5236124?v=4)](https://github.com/coldume "coldume (7 commits)")[![Tiross](https://avatars.githubusercontent.com/u/4322225?v=4)](https://github.com/Tiross "Tiross (7 commits)")[![PotcFdk](https://avatars.githubusercontent.com/u/3160048?v=4)](https://github.com/PotcFdk "PotcFdk (1 commits)")[![stevecoug](https://avatars.githubusercontent.com/u/432808?v=4)](https://github.com/stevecoug "stevecoug (1 commits)")

---

Tags

thumbnailimagegdresizewatermarkanimation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tiross-imagecraft/health.svg)

```
[![Health](https://phpackages.com/badges/tiross-imagecraft/health.svg)](https://phpackages.com/packages/tiross-imagecraft)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[coldume/imagecraft

A reliable and extensible PHP image manipulation library

10133.7k2](/packages/coldume-imagecraft)[sybio/image-workshop

Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)

860918.1k11](/packages/sybio-image-workshop)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[jbzoo/image

A PHP class that simplifies working with images

171126.9k3](/packages/jbzoo-image)[folklore/image

Image manipulation library for Laravel 5 based on Imagine and inspired by Croppa for easy url based manipulation

270248.2k5](/packages/folklore-image)

PHPackages © 2026

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