Skip to content

Commit

Permalink
Add Symfony Image Component
Browse files Browse the repository at this point in the history
This component is a port of Bulat Shakirzyanov's Imagine library (https://github.com/avalanche123/Imagine) into Symfony.
  • Loading branch information
avalanche123 authored and romainneutron committed Mar 1, 2017
1 parent 28a00da commit dcd13b3
Show file tree
Hide file tree
Showing 217 changed files with 16,867 additions and 2 deletions.
13 changes: 11 additions & 2 deletions .travis.yml
Expand Up @@ -11,6 +11,12 @@ addons:
- language-pack-fr-base
- ldap-utils
- slapd
- libtiff-dev
- libjpeg-dev
- libdjvulibre-dev
- libwmf-dev
- pkg-config
- liblcms2-dev

env:
global:
Expand All @@ -27,15 +33,16 @@ matrix:
- php: 5.5
- php: 5.6
- php: 7.0
env: deps=high
env: deps=high IMAGE_DRIVER=gmagick
- php: 7.1
env: deps=low
env: deps=low IMAGE_DRIVER=imagick
fast_finish: true

cache:
directories:
- .phpunit
- php-$MIN_PHP
- cache

services:
- memcached
Expand Down Expand Up @@ -89,6 +96,8 @@ install:
- if [[ ! $skip ]]; then composer update; fi
- if [[ ! $skip ]]; then ./phpunit install; fi
- if [[ ! $skip && ! $PHP = hhvm* ]]; then php -i; else hhvm --php -r 'print_r($_SERVER);print_r(ini_get_all());'; fi
- if [[ $IMAGE_DRIVER = imagick ]]; then bash ./.travis/imagick.sh; fi
- if [[ $IMAGE_DRIVER = gmagick ]]; then bash ./.travis/gmagick.sh; fi

script:
- REPORT=' && echo -e "\\e[32mOK\\e[0m {}\\n\\n" || (echo -e "\\e[41mKO\\e[0m {}\\n\\n" && $(exit 1))'
Expand Down
46 changes: 46 additions & 0 deletions .travis/gmagick.sh
@@ -0,0 +1,46 @@
#!/bin/bash

set -xe

GRAPHICSMAGIC_VERSION="1.3.23"
if [ $TRAVIS_PHP_VERSION = '7.0' ] || [ $TRAVIS_PHP_VERSION = '7.1' ]
then
GMAGICK_VERSION="2.0.4RC1"
else
GMAGICK_VERSION="1.1.7RC2"
fi

mkdir -p cache
cd cache

if [ ! -e ./GraphicsMagick-$GRAPHICSMAGIC_VERSION ]
then
wget http://78.108.103.11/MIRROR/ftp/GraphicsMagick/1.3/GraphicsMagick-$GRAPHICSMAGIC_VERSION.tar.xz
tar -xf GraphicsMagick-$GRAPHICSMAGIC_VERSION.tar.xz
rm GraphicsMagick-$GRAPHICSMAGIC_VERSION.tar.xz
cd GraphicsMagick-$GRAPHICSMAGIC_VERSION
./configure --prefix=$HOME/opt/gmagick --enable-shared --with-lcms2
make -j
else
cd GraphicsMagick-$GRAPHICSMAGIC_VERSION
fi

make install
cd ..

if [ ! -e ./gmagick-$GMAGICK_VERSION ]
then
wget https://pecl.php.net/get/gmagick-$GMAGICK_VERSION.tgz
tar -xzf gmagick-$GMAGICK_VERSION.tgz
rm gmagick-$GMAGICK_VERSION.tgz
cd gmagick-$GMAGICK_VERSION
phpize
./configure --with-gmagick=$HOME/opt/gmagick
make -j
else
cd gmagick-$GMAGICK_VERSION
fi

make install
echo "extension=gmagick.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
php --ri gmagick
43 changes: 43 additions & 0 deletions .travis/imagick.sh
@@ -0,0 +1,43 @@
#!/bin/bash

set -xe

IMAGEMAGICK_VERSION="6.8.9-10"
IMAGICK_VERSION="3.4.3"

mkdir -p cache
cd cache

if [ ! -e ./ImageMagick-$IMAGEMAGICK_VERSION ]
then
wget http://www.imagemagick.org/download/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz
tar -xf ImageMagick-$IMAGEMAGICK_VERSION.tar.xz
rm ImageMagick-$IMAGEMAGICK_VERSION.tar.xz
cd ImageMagick-$IMAGEMAGICK_VERSION
./configure --prefix=$HOME/opt/imagemagick
make -j
else
cd ImageMagick-$IMAGEMAGICK_VERSION
fi

make install
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/opt/imagemagick/lib/pkgconfig
ln -s $HOME/opt/imagemagick/include/ImageMagick-6 $HOME/opt/imagemagick/include/ImageMagick
cd ..

if [ ! -e ./imagick-$IMAGICK_VERSION ]
then
wget https://pecl.php.net/get/imagick-$IMAGICK_VERSION.tgz
tar -xzf imagick-$IMAGICK_VERSION.tgz
rm imagick-$IMAGICK_VERSION.tgz
cd imagick-$IMAGICK_VERSION
phpize
./configure --with-imagick=$HOME/opt/imagemagick
make -j
else
cd imagick-$IMAGICK_VERSION
fi

make install
echo "extension=imagick.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
php --ri imagick
5 changes: 5 additions & 0 deletions src/Symfony/Component/Image/.gitignore
@@ -0,0 +1,5 @@
composer.lock
phpunit.xml
vendor/
Tests/Fixtures/results/in_out
!Tests/Fixtures/results/in_out/.placeholder
146 changes: 146 additions & 0 deletions src/Symfony/Component/Image/Draw/DrawerInterface.php
@@ -0,0 +1,146 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Image\Draw;

use Symfony\Component\Image\Image\AbstractFont;
use Symfony\Component\Image\Image\BoxInterface;
use Symfony\Component\Image\Image\Palette\Color\ColorInterface;
use Symfony\Component\Image\Image\PointInterface;
use Symfony\Component\Image\Exception\RuntimeException;

interface DrawerInterface
{
/**
* Draws an arc on a starting at a given x, y coordinates under a given
* start and end angles.
*
* @param PointInterface $center
* @param BoxInterface $size
* @param int $start
* @param int $end
* @param ColorInterface $color
* @param int $thickness
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function arc(PointInterface $center, BoxInterface $size, $start, $end, ColorInterface $color, $thickness = 1);

/**
* Same as arc, but also connects end points with a straight line.
*
* @param PointInterface $center
* @param BoxInterface $size
* @param int $start
* @param int $end
* @param ColorInterface $color
* @param bool $fill
* @param int $thickness
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function chord(PointInterface $center, BoxInterface $size, $start, $end, ColorInterface $color, $fill = false, $thickness = 1);

/**
* Draws and ellipse with center at the given x, y coordinates, and given
* width and height.
*
* @param PointInterface $center
* @param BoxInterface $size
* @param ColorInterface $color
* @param bool $fill
* @param int $thickness
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function ellipse(PointInterface $center, BoxInterface $size, ColorInterface $color, $fill = false, $thickness = 1);

/**
* Draws a line from start(x, y) to end(x, y) coordinates.
*
* @param PointInterface $start
* @param PointInterface $end
* @param ColorInterface $outline
* @param int $thickness
*
* @return DrawerInterface
*/
public function line(PointInterface $start, PointInterface $end, ColorInterface $outline, $thickness = 1);

/**
* Same as arc, but connects end points and the center.
*
* @param PointInterface $center
* @param BoxInterface $size
* @param int $start
* @param int $end
* @param ColorInterface $color
* @param bool $fill
* @param int $thickness
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function pieSlice(PointInterface $center, BoxInterface $size, $start, $end, ColorInterface $color, $fill = false, $thickness = 1);

/**
* Places a one pixel point at specific coordinates and fills it with
* specified color.
*
* @param PointInterface $position
* @param ColorInterface $color
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function dot(PointInterface $position, ColorInterface $color);

/**
* Draws a polygon using array of x, y coordinates. Must contain at least
* three coordinates.
*
* @param array $coordinates
* @param ColorInterface $color
* @param bool $fill
* @param int $thickness
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function polygon(array $coordinates, ColorInterface $color, $fill = false, $thickness = 1);

/**
* Annotates image with specified text at a given position starting on the
* top left of the final text box.
*
* The rotation is done CW
*
* @param string $string
* @param AbstractFont $font
* @param PointInterface $position
* @param int $angle
* @param int $width
*
* @throws RuntimeException
*
* @return DrawerInterface
*/
public function text($string, AbstractFont $font, PointInterface $position, $angle = 0, $width = null);
}
78 changes: 78 additions & 0 deletions src/Symfony/Component/Image/Effects/EffectsInterface.php
@@ -0,0 +1,78 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Image\Effects;

use Symfony\Component\Image\Exception\RuntimeException;
use Symfony\Component\Image\Image\Palette\Color\ColorInterface;

interface EffectsInterface
{
/**
* Apply gamma correction.
*
* @param float $correction
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function gamma($correction);

/**
* Invert the colors of the image.
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function negative();

/**
* Grayscale the image.
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function grayscale();

/**
* Colorize the image.
*
* @param ColorInterface $color
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function colorize(ColorInterface $color);

/**
* Sharpens the image.
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function sharpen();

/**
* Blur the image.
*
* @param float|int $sigma
*
* @return EffectsInterface
*
* @throws RuntimeException
*/
public function blur($sigma);
}
16 changes: 16 additions & 0 deletions src/Symfony/Component/Image/Exception/ExceptionInterface.php
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Image\Exception;

interface ExceptionInterface
{
}
16 changes: 16 additions & 0 deletions src/Symfony/Component/Image/Exception/InvalidArgumentException.php
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Image\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}

0 comments on commit dcd13b3

Please sign in to comment.