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

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

jbzoo/image
===========

A PHP class that simplifies working with images

7.0.2(7mo ago)171126.9k↓33.8%12[3 issues](https://github.com/JBZoo/Image/issues)3MITPHPPHP ^8.2CI passing

Since Aug 7Pushed 7mo ago7 watchersCompare

[ Source](https://github.com/JBZoo/Image)[ Packagist](https://packagist.org/packages/jbzoo/image)[ RSS](/packages/jbzoo-image/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (33)Used By (3)

JBZoo / Image
=============

[](#jbzoo--image)

[![CI](https://github.com/JBZoo/Image/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Image/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://camo.githubusercontent.com/41ff52ac8be2c48dc8b0d096df6a6c566887e904bb240424cfdf52027281a00f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f496d6167652f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/Image?branch=master) [![Psalm Coverage](https://camo.githubusercontent.com/7c449a66a7f383277fd27ad00959a222b84b7076d73b91f8c46789591fa59472/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f496d6167652f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/Image) [![Psalm Level](https://camo.githubusercontent.com/cbf88b9046ef8b68a64b6e8b6810e0c660339a5a2c0ec6ffc767aa379b795890/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f496d6167652f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/Image) [![CodeFactor](https://camo.githubusercontent.com/952812f7782c1882ed50101cc39a1bf1186af7da1ffbdab85ec2e4fc17c36980/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f696d6167652f6261646765)](https://www.codefactor.io/repository/github/jbzoo/image/issues)[![Stable Version](https://camo.githubusercontent.com/9e5e37ab3514d690e771b50affd74c513bd83eeff7d2fe0dd412ea1ccd92ade8/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f696d6167652f76657273696f6e)](https://packagist.org/packages/jbzoo/image/) [![Total Downloads](https://camo.githubusercontent.com/72a8331b4c47126b8572139a9820acb36aa186c48bfda2bba782f3a07a58a27b/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f696d6167652f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/image/stats) [![Dependents](https://camo.githubusercontent.com/36552392f50157ff003c79e7b63eb772da7633c9028fe0fbf627b92d321b8952/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f696d6167652f646570656e64656e7473)](https://packagist.org/packages/jbzoo/image/dependents?order_by=downloads) [![GitHub License](https://camo.githubusercontent.com/eba9b74e0f8dc3eadf53d2b9e7cff50c096c91c2abb622a0d021e2c55f5510c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f696d616765)](https://github.com/JBZoo/Image/blob/master/LICENSE)

A powerful and intuitive PHP library for image manipulation that provides an object-oriented way to work with images as simply as possible. Built on top of PHP's GD extension with support for modern PHP versions (8.2+).

Features
--------

[](#features)

- **Multiple Image Formats**: GIF, JPEG, PNG, and WEBP support
- **Flexible Resizing**: Free resize, fit to width/height, best fit, and smart thumbnails
- **Image Filters**: 15+ built-in filters including grayscale, sepia, blur, pixelate, and more
- **Text Overlays**: Add text with custom fonts, colors, positioning, and effects
- **Watermarking**: Overlay images with transparency and positioning control
- **Format Conversion**: Convert between different image formats on save
- **EXIF Handling**: Automatic orientation correction and EXIF data preservation
- **Method Chaining**: Fluent interface for readable code
- **Memory Efficient**: Proper resource management and cleanup

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- GD extension (with JPEG, PNG, GIF support)
- EXIF extension (for automatic orientation)
- CTYPE extension

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

[](#installation)

```
composer require jbzoo/image
```

Quick Start
-----------

[](#quick-start)

```
use JBZoo\Image\Image;

$img = (new Image('./example/source-image.jpg'))
    ->addFilter('flip', 'x')
    ->addFilter('text', 'Some text', './res/font.ttf')
    ->thumbnail(320, 240)
    ->saveAs('./example/dist-image.png');
```

This example loads `source-image.jpg`, flips it horizontally, adds text with a custom font, creates a 320×240 thumbnail, and saves it as a PNG.

Comprehensive Usage
-------------------

[](#comprehensive-usage)

```
use JBZoo\Image\Image;
use JBZoo\Image\Filter;
use JBZoo\Image\Exception;

try { // Error handling

    $img = (new Image('./some-path/image.jpg'))     // You can load an image when you instantiate a new Image object
        ->loadFile('./some-path/another-path.jpg')  // Load another file (replace internal state)

        // Saving
        ->save()   // Images must be saved after you manipulate them. To save your changes to the original file.
        ->save(90) // Specify quality (0 to 100)

        // Save as new file
        ->saveAs('./some-path/new-image.jpg')     // Alternatively, you can specify a new filename
        ->saveAs('./some-path/new-image.jpg', 90) // You can specify quality as a second parameter in percents within range 0-100
        ->saveAs('./some-path/new-image.png')     // Or convert it into another format by extention (gif|jpeg|png|webp)

        // Resizing
        ->resize(320, 200)          // Resize the image to 320x200
        ->thumbnail(100, 75)        // Trim the image and resize to exactly 100x75 (crop CENTER if needed)
        ->thumbnail(100, 75, true)  // Trim the image and resize to exactly 100x75 (crop TOP if needed)
        ->fitToWidth(320)           // Shrink the image to the specified width while maintaining proportion (width)
        ->fitToHeight(200)          // Shrink the image to the specified height while maintaining proportion (height)
        ->bestFit(500, 500)         // Shrink the image proportionally to fit inside a 500x500 box
        ->crop(100, 100, 400, 400)  // Crop a portion of the image from left, top, right, bottom

        // Filters
        ->addFilter('sepia')                        // Sepia effect (simulated)
        ->addFilter('grayscale')                    // Grayscale
        ->addFilter('desaturate', 50)               // Desaturate
        ->addFilter('pixelate', 8)                  // Pixelate using 8px blocks
        ->addFilter('edges')                        // Edges filter
        ->addFilter('emboss')                       // Emboss filter
        ->addFilter('invert')                       // Invert colors
        ->addFilter('blur', Filter::BLUR_SEL)       // Selective blur (one pass)
        ->addFilter('blur', Filter::BLUR_GAUS, 2)   // Gaussian blur (two passes)
        ->addFilter('brightness', 100)              // Adjust Brightness (-255 to 255)
        ->addFilter('contrast', 50)                 // Adjust Contrast (-100 to 100)
        ->addFilter('colorize', '#FF0000', .5)      // Colorize red at 50% opacity
        ->addFilter('meanRemove')                   // Mean removal filter
        ->addFilter('smooth', 5)                    // Smooth filter (-10 to 10)
        ->addFilter('opacity', .5)                  // Change opacity
        ->addFilter('rotate', 90)                   // Rotate the image 90 degrees clockwise
        ->addFilter('flip', 'x')                    // Flip the image horizontally
        ->addFilter('flip', 'y')                    // Flip the image vertically
        ->addFilter('flip', 'xy')                   // Flip the image horizontally and vertically
        ->addFilter('fill', '#fff')                 // Fill image with white color

        // Custom filter handler
        ->addFilter(function ($image, $blockSize) {
            imagefilter($image, IMG_FILTER_PIXELATE, $blockSize, true);
        }, 2) // $blockSize = 2

        // Overlay watermark.png at 50% opacity at the bottom-right of the image with a 10 pixel horz and vert margin
        ->overlay('./image/watermark.png', 'bottom right', .5, -10, -10)

        // Other
        ->create(200, 100, '#000') // Create empty image 200x100 with black background
        ->setQuality(95)           // Set new internal quality state
        ->autoOrient()             // Adjust the orientation if needed (physically rotates/flips the image based on its EXIF 'Orientation' property)
    ;

} catch(Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
```

Image Creation Methods
----------------------

[](#image-creation-methods)

```
// Filename
$img = new Image('./path/to/image.png');

// Base64 format
$img = new Image('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

// Image string
$img = new Image('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

// Some binary data
$imgBin = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
$img = new Image($imgBin);

// Resource
$imgRes = imagecreatefromjpeg('./some-image.jpeg');
$img = new Image($imgRes);
```

Utility Methods
---------------

[](#utility-methods)

```
$img = new Image($_SERVER['DOCUMENT_ROOT'] . '/resources/butterfly.jpg');

$img->getBase64();                  // Get base64 as string (format from inner state)
$img->getBase64('gif');             // Convert to GIF and get base64 as string
$img->getBase64('jpeg', 85);        // Convert to JPEG (q=85%) and get base64 as string
$img->getBase64('png', 100, false); // Get only base64 without mime header

$img->getBinary();              // Get clean binary data (format from inner state)
$img->getBinary('jpeg', 85);    // Binary in JPEG format with quality 85%

$img->getHeight();      // Height in px
$img->getWidth();       // Width in px
$img->cleanup();        // Full cleanup of internal state of object
$img->getImage();       // Get GD Image resource

$img->isGif();          // Check format
$img->isJpeg();         // Check format
$img->isPng();          // Check format

$img->isPortrait();     // Check orientation
$img->isLandscape();    // Check orientation
$img->isSquare();       // Check orientation

$img->getUrl();         // Get full url to image     - http://site.com/resources/butterfly.jpg
$img->getPath();        // Get relative url to image - /resources/butterfly.jpg

$imgInfo = $img->getInfo(); // Get array of all properties

// It will be something like that ...
$imgInfo = [
    "filename" => "//resources/butterfly.jpg",
    "width"    => 640,
    "height"   => 478,
    "mime"     => "image/jpeg",
    "quality"  => 95,
    "exif"     => [
        "FileName"      => "butterfly.jpg",
        "FileDateTime"  => 1454653291,
        "FileSize"      => 280448,
        "FileType"      => 2,
        "MimeType"      => "image/jpeg",
        "SectionsFound" => "",
        "COMPUTED"      => [
            "html"    => 'width="640" height="478"',
            "Height"  => 478,
            "Width"   => 640,
            "IsColor" => 1,
        ],
    ],
    "orient"   => "landscape",
];
```

Text Overlays
-------------

[](#text-overlays)

```
$img = new Image('./resources/butterfly.jpg');
$img->addFilter(
    'text',                             // Filter name
    'Some image description',           // Text to render on image
    './resources/font.ttf'              // TTF font file
    [                                   // Additionals params
        'font-size'      => 48,                       // Font size in px
        'color'          => array('#ff7f00', '#f00'), // Or one color as string

        // Stroke
        'stroke-color'   => array('#f00', '#ff7f00'), // Or one color as string
        'stroke-size'    => 3,                        // Stroke size in px
        'stroke-spacing' => 5,                        // Letter spacing in px (only for stroke mode)

        // Position of text
        'offset-x'       => -140,       // X offset in px
        'offset-y'       => 100,        // Y offset in px
        'position'       => 't',        // top|t|Helper::TOP| ... More details in the method Helper::position()

        // Experimental
        'angle'          => 0,          // Angle for each letter
    ])
    ->saveAs('./dist/new-file.png');    // Save it to new file
```

Development
-----------

[](#development)

### Setup

[](#setup)

```
make update    # Install/update dependencies
```

### Testing

[](#testing)

```
make test      # Run PHPUnit tests
make test-all  # Run tests and code quality checks
```

### Code Quality

[](#code-quality)

```
make codestyle # Run linters and code style checks
```

License
-------

[](#license)

MIT

See Also
--------

[](#see-also)

- [CI-Report-Converter](https://github.com/JBZoo/CI-Report-Converter) - The tool converts different error reporting standards for deep compatibility with popular CI systems.
- [Composer-Diff](https://github.com/JBZoo/Composer-Diff) - See what packages have changed after `composer update`.
- [Composer-Graph](https://github.com/JBZoo/Composer-Graph) - Dependency graph visualization for composer.json (PHP + Composer) based on mermaid-js.
- [Mermaid-PHP](https://github.com/JBZoo/Mermaid-PHP) - Generate diagrams and flowcharts with the help of the mermaid script language.
- [Utils](https://github.com/JBZoo/Utils) - Collection of useful PHP functions, mini-classes, and snippets for every day.
- [Data](https://github.com/JBZoo/Data) - Extended implementation of ArrayObject. Use files as config/array.
- [Retry](https://github.com/JBZoo/Retry) - Tiny PHP library providing retry/backoff functionality with multiple backoff strategies and jitter support.
- [SimpleTypes](https://github.com/JBZoo/SimpleTypes) - Converting any values and measures - money, weight, exchange rates, length, ...

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance62

Regular maintenance activity

Popularity48

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

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

Recently: every ~301 days

Total

32

Last Release

233d ago

Major Versions

2.6.0 → 3.0.02016-02-13

3.0.5 → 4.0.02019-11-24

4.0.1 → 5.0.02020-07-14

5.3.0 → 6.0.02022-06-09

6.0.0 → 7.0.02023-07-09

PHP version history (8 changes)2.3.1PHP &gt;=5.3.0

3.0.0PHP &gt;=5.3.10

4.0.0PHP &gt;=7.1

5.0.0PHP &gt;=7.2

5.0.1PHP ^7.2

6.0.0PHP ^8.0

7.0.0PHP ^8.1

7.0.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e6de2785f6d099699f430ff58404af4fc0e83060d2953028c9664a54704a5f?d=identicon)[smetdenis](/maintainers/smetdenis)

---

Top Contributors

[![claviska](https://avatars.githubusercontent.com/u/55639?v=4)](https://github.com/claviska "claviska (111 commits)")[![SmetDenis](https://avatars.githubusercontent.com/u/1118678?v=4)](https://github.com/SmetDenis "SmetDenis (100 commits)")[![nazar-pc](https://avatars.githubusercontent.com/u/928965?v=4)](https://github.com/nazar-pc "nazar-pc (22 commits)")[![mikedidomizio](https://avatars.githubusercontent.com/u/5728044?v=4)](https://github.com/mikedidomizio "mikedidomizio (17 commits)")[![hikouki](https://avatars.githubusercontent.com/u/15326035?v=4)](https://github.com/hikouki "hikouki (9 commits)")[![melihucar](https://avatars.githubusercontent.com/u/982959?v=4)](https://github.com/melihucar "melihucar (6 commits)")[![Tampler6](https://avatars.githubusercontent.com/u/5604423?v=4)](https://github.com/Tampler6 "Tampler6 (1 commits)")[![josepanguera](https://avatars.githubusercontent.com/u/1191968?v=4)](https://github.com/josepanguera "josepanguera (1 commits)")[![arrisco](https://avatars.githubusercontent.com/u/535076?v=4)](https://github.com/arrisco "arrisco (1 commits)")

---

Tags

convertercropgdimageimage-processingimagesjbzooresizethumbnailwatermarkthumbnailimagegdresizewatermarkimagescropfiltersjbzoo

### Embed Badge

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

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

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[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)[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)[coldume/imagecraft

A reliable and extensible PHP image manipulation library

10133.7k2](/packages/coldume-imagecraft)[intervention/image-symfony

Symfony Integration of Intervention Image

1066.8k](/packages/intervention-image-symfony)

PHPackages © 2026

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