GithubHelp home page GithubHelp logo

imagine-svg's Introduction

Contao Imagine SVG library

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.

Installation

php composer.phar require contao/imagine-svg

Usage

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

$imagine = new Imagine();

$imagine
    ->open('/path/to/image.svg')
    ->crop(new Point(50, 50), new Box(100, 100))
    ->resize(new Box(40, 40))
    ->save('/path/to/thumbnail.svg')
;

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

$image->effects()
    ->gamma(1.5)
    ->negative()
    ->grayscale()
    ->colorize($color)
    ->sharpen()
    ->blur(2)
;

$image->save('/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\RelativeBoxInterface;
use Contao\ImagineSvg\UndefinedBoxInterface;

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

if ($size instanceof UndefinedBoxInterface) {
    // The image has no defined size
} elseif ($size instanceof RelativeBoxInterface) {
    // 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
}

imagine-svg's People

Contributors

ausi avatar chregu avatar leofeyer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.