Contao Imagine SVG library

Fund package maintenance!

Installs: 1 213 696

Dependents: 9

Suggesters: 1

Security: 0

Stars: 65

Watchers: 5

Forks: 9

Open Issues: 0

1.0.3 2021-08-10 09:33 UTC

This package is auto-updated.

Last update: 2022-07-20 10:09:19 UTC


This project implements the interfaces of Imagine and allows you to make simple modifications to SVG images. It is used in Contao to handle on-the-fly resizing of SVG images.


php composer.phar require contao/imagine-svg


use Contao\ImagineSvg\Imagine;
use Imagine\Image\Box;
use Imagine\Image\Point;

$imagine = new Imagine();

    ->crop(new Point(50, 50), new Box(100, 100))
    ->resize(new Box(40, 40))

$image = $imagine->open('/path/to/image.svg');



Because of the nature of SVG images, the getSize() method differs a little bit from other implementations. You can check the return value like in this example:

use Contao\ImagineSvg\Imagine;
use Contao\ImagineSvg\SvgBox;

$imagine = new Imagine();
$size = $imagine->open('/path/to/image.svg')->getSize();

if (SvgBox::TYPE_NONE === $size->getType()) {
    // The image has no defined size
} elseif (SvgBox::TYPE_ASPECT_RATIO === $size->getType()) {
    // The image has a relative size, $size->getWidth() and $size->getHeight()
    // should be treated as an aspect ratio
} else {
    // The image has a defined size like a regular image
    // $size->getType() would return SvgBox::TYPE_ABSOLUTE in this case