Skip to content

Add Symfony Image Component #21820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/gmagick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

set -xe

if [ -z "$1" ]
then
echo "You must provide the PHP version as first argument"
exit 1
fi

if [ -z "$2" ]
then
echo "You must provide the php.ini path as second argument"
exit 1
fi

PHP_VERSION=$1
PHP_INI_FILE=$2

GRAPHICSMAGIC_VERSION="1.3.23"
if [ $PHP_VERSION = '7.0' ] || [ $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=`pwd`/modules/gmagick.so" >> $PHP_INI_FILE
php --ri gmagick
51 changes: 51 additions & 0 deletions .github/imagick.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

set -xe

if [ -z "$1" ]
then
echo "You must provide the php.ini path as first argument"
exit 1
fi

PHP_INI_FILE=$1

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

mkdir -p cache
cd cache

if [ ! -e ./ImageMagick-$IMAGEMAGICK_VERSION ]
then
wget https://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=`pwd`/modules/imagick.so" >> $PHP_INI_FILE
php --ri imagick
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
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 @@ -26,16 +32,18 @@ matrix:
group: edge
- php: 5.5
- php: 5.6
env: IMAGE_DRIVER=gmagick
- php: 7.0
env: deps=high
- 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 @@ -90,6 +98,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 ./.github/imagick.sh $INI_FILE; fi
- if [[ $IMAGE_DRIVER = gmagick ]]; then ./.github/gmagick.sh $TRAVIS_PHP_VERSION $INI_FILE; fi

script:
- REPORT=' && echo -e "\\e[32mOK\\e[0m {}\\n\\n" || (echo -e "\\e[41mKO\\e[0m {}\\n\\n" && $(exit 1))'
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ install:
- echo apc.enable_cli=1 >> php.ini-max
- echo extension=php_memcache.dll >> php.ini-max
- echo extension=php_intl.dll >> php.ini-max
- echo extension=php_exif.dll >> php.ini-max
- echo extension=php_gd2.dll >> php.ini-max
- echo extension=php_mbstring.dll >> php.ini-max
- echo extension=php_fileinfo.dll >> php.ini-max
- echo extension=php_pdo_sqlite.dll >> php.ini-max
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"ocramius/proxy-manager": "~0.4|~1.0|~2.0",
"predis/predis": "~1.0",
"egulias/email-validator": "~1.2,>=1.2.8|~2.0",
"symfony/image-fixtures": "dev-master@dev",
"symfony/phpunit-bridge": "~3.2",
"symfony/polyfill-apcu": "~1.1",
"symfony/security-acl": "~2.8|~3.0",
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Image/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
composer.lock
phpunit.xml
vendor/
7 changes: 7 additions & 0 deletions src/Symfony/Component/Image/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGELOG
=========

3.3.0
-----

* [EXPERIMENTAL] added the component
146 changes: 146 additions & 0 deletions src/Symfony/Component/Image/Draw/DrawerInterface.php
Original file line number Diff line number Diff line change
@@ -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);
}
Loading