PHP Image library for generating, editing and effecting images. A component of the Pop PHP Framework

3.5.0 2021-02-12 05:51 UTC


Build Status Coverage Status


pop-image is a powerful and robust image processing component that's simple to use. It supports the GD and Imagick extensions. The API is similar to the more popular image editing application on the market, with calls to manipulation objects that can be extended with additional image processing functionality if needed

pop-image is a component of the Pop PHP Framework.


Install pop-image using Composer.

composer require popphp/pop-image


Resizing and saving an image

use Pop\Image\Image;

$img = Image::loadGd('image.jpg');



Using the manipulation objects

There are 6 available manipulation objects. They are:

  • Adjust
  • Draw
  • Effect
  • Filter
  • Layer
  • Type

With each of these, you can perform advanced image processing manipulation on an image. If a feature doesn't exist yet, you can extend these classes to add your own custom features.

use Pop\Image\Image;
use Pop\Image\Color\Rgb;

$img = Image::loadImagick('image.jpg');

$img->draw->setFillColor(new Rgb(255, 0, 0))
    ->rectangle(200, 200, 100, 50);

$img->effect->verticalGradient(new Rgb(255, 0, 0), new Rgb(0, 0, 255));


$img->layer->overlay('watermark.png', 200, 200);

    ->xy(50, 100)
    ->text('Hello World!');


The pop-image component comes with a CAPTCHA tool to create a CAPTCHA image and store the token value in session to validate the user's CAPTCHA input.

$captcha = new Pop\Image\Captcha('/captcha.php');
header('Content-Type: image/gif');
echo $captcha;

The script above will generate the following image:


And with it, the $_SESSION variable will store a pop_captcha key with a serialized value in it. When you unserialized the $_SESSION['pop_captcha'] value, it will give you this array:

    [captcha] => <img id="pop-captcha-image" class="pop-captcha-image" src="/captcha.php" /><a class="pop-captcha-reload" href="#" onclick="document.getElementById('pop-captcha-image').src = '/captcha.php?captcha=1'; return false;">Reload</a>
    [answer]  => DWB6
    [expire]  => 300
    [start]   => 1574265980

You can use the captcha value to display the image in an HTML page and the answer value to validate the user's CAPTCHA input.