Commit 2df7d0a8 by Qiang Xue

Merge branch '46-image-helper' of github.com:tonydspaniard/yii2 into tonydspaniard-46-image-helper

Conflicts: composer.json
parents 011c6c14 52ad66e3
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
"yiisoft/yii2-codeception": "self.version", "yiisoft/yii2-codeception": "self.version",
"yiisoft/yii2-debug": "self.version", "yiisoft/yii2-debug": "self.version",
"yiisoft/yii2-elasticsearch": "self.version", "yiisoft/yii2-elasticsearch": "self.version",
"yiisoft/yii2-imagine": "self.version",
"yiisoft/yii2-gii": "self.version", "yiisoft/yii2-gii": "self.version",
"yiisoft/yii2-jui": "self.version", "yiisoft/yii2-jui": "self.version",
"yiisoft/yii2-mongodb": "self.version", "yiisoft/yii2-mongodb": "self.version",
...@@ -76,10 +77,6 @@ ...@@ -76,10 +77,6 @@
"michelf/php-markdown": "1.3.*" "michelf/php-markdown": "1.3.*"
}, },
"require-dev": { "require-dev": {
"twbs/bootstrap": "3.0.*",
"smarty/smarty": "*",
"swiftmailer/swiftmailer": "*",
"twig/twig": "*",
"phpunit/phpunit": "3.7.*" "phpunit/phpunit": "3.7.*"
}, },
"suggest": { "suggest": {
...@@ -88,6 +85,7 @@ ...@@ -88,6 +85,7 @@
"ext-mongo": "required by yii2-mongo extension", "ext-mongo": "required by yii2-mongo extension",
"ext-pdo": "required by yii2-sphinx extension", "ext-pdo": "required by yii2-sphinx extension",
"ext-pdo_mysql": "required by yii2-sphinx extension", "ext-pdo_mysql": "required by yii2-sphinx extension",
"imagine/imagine": "required by yii2-imagine extension",
"smarty/smarty": "required by yii2-smarty extension", "smarty/smarty": "required by yii2-smarty extension",
"swiftmailer/swiftmailer": "required by yii2-swiftmailer extension", "swiftmailer/swiftmailer": "required by yii2-swiftmailer extension",
"twig/twig": "required by yii2-twig extension" "twig/twig": "required by yii2-twig extension"
...@@ -100,6 +98,7 @@ ...@@ -100,6 +98,7 @@
"yii\\debug\\": "extensions/", "yii\\debug\\": "extensions/",
"yii\\elasticsearch\\": "extensions/", "yii\\elasticsearch\\": "extensions/",
"yii\\gii\\": "extensions/", "yii\\gii\\": "extensions/",
"yii\\imagine\\" : "extensions/",
"yii\\jui\\": "extensions/", "yii\\jui\\": "extensions/",
"yii\\mongodb\\": "extensions/", "yii\\mongodb\\": "extensions/",
"yii\\redis\\": "extensions/", "yii\\redis\\": "extensions/",
......
Yii Framework 2 imagine extension Change Log
================================================
2.0.0 beta under development
----------------------------
- no changes in this release.
2.0.0 alpha, December 1, 2013
-----------------------------
- Initial release.
The Yii framework is free software. It is released under the terms of
the following BSD License.
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Yii Software LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Image Extension for Yii 2
==============================
This extension adds most common image functions and also acts as a wrapper to [Imagine](http://imagine.readthedocs.org/)
image manipulation library.
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require yiisoft/yii2-imagine "*"
```
or add
```json
"yiisoft/yii2-imagine": "*"
```
to the `require` section of your composer.json.
Usage & Documentation
---------------------
This extension is a wrapper to the [Imagine](http://imagine.readthedocs.org/) and also adds the most common methods
used for Image manipulation.
To use this extension, you can use it in to ways, whether you configure it on your application file or you use it
directly.
The following shows how to use it via application configuration file:
```
// configuring on your application configuration file
'components' => [
'image' => [
'class' => 'yii\imagine\Image',
'driver' => \yii\imagine\Image::DRIVER_GD2,
]
...
]
// Once configured you can access to the extension like this:
$img = Yii::$app->image->thumb('path/to/image.jpg', 120, 120);
```
This is how to use it directly:
```
use yii\imagine\Image;
$image = new Image();
$img = $image->thumb('path/to/image.jpg', 120, 120);
```
**About the methods**
Each method returns an instance to `\Imagine\Image\ManipulatorInterface`, that means that you can easily make use of the methods included in the `Imagine` library:
```
// frame, rotate and save an image
Yii::$app->image->frame('path/to/image.jpg', 5, '666', 0)
->rotate(-8)
->save('path/to/destination/image.jpg', ['quality' => 50]);
```
\ No newline at end of file
{
"name": "yiisoft/yii2-imagine",
"description": "The Imagine integration for the Yii framework",
"keywords": ["yii", "imagine", "image", "helper"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Aimagine",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"authors": [
{
"name": "Antonio Ramirez",
"email": "amigo.cobos@gmail.com"
}
],
"require": {
"yiisoft/yii2": "*",
"imagine/imagine": "v0.5.0"
},
"autoload": {
"psr-0": {
"yii\\imagine\\": ""
}
},
"target-dir": "yii/imagine"
}
...@@ -24,6 +24,7 @@ Yii Framework 2 Change Log ...@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe) - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
- Bug: Fixed issue with tabular input on ActiveField::radio() and ActiveField::checkbox() (jom) - Bug: Fixed issue with tabular input on ActiveField::radio() and ActiveField::checkbox() (jom)
- Bug: Fixed the issue that query cache returns the same data for the same SQL but different query methods (qiangxue) - Bug: Fixed the issue that query cache returns the same data for the same SQL but different query methods (qiangxue)
- Enh #46: Added Image extension based on [Imagine library](http://imagine.readthedocs.org) (tonydspaniard)
- Enh #364: Improve Inflector::slug with `intl` transliteration. Improved transliteration char map. (tonydspaniard) - Enh #364: Improve Inflector::slug with `intl` transliteration. Improved transliteration char map. (tonydspaniard)
- Enh #797: Added support for validating multiple columns by `UniqueValidator` and `ExistValidator` (qiangxue) - Enh #797: Added support for validating multiple columns by `UniqueValidator` and `ExistValidator` (qiangxue)
- Enh #802: Added support for retrieving sub-array element or child object property through `ArrayHelper::getValue()` (qiangxue, cebe) - Enh #802: Added support for retrieving sub-array element or child object property through `ArrayHelper::getValue()` (qiangxue, cebe)
......
<?php
namespace yiiunit\extensions\imagine;
use Yii;
use Imagine\Image\Point;
use yiiunit\VendorTestCase;
Yii::setAlias('@yii/imagine', __DIR__ . '/../../../../extensions/yii/imagine');
abstract class AbstractImageTest extends VendorTestCase
{
/**
* @var yii\imagine\Image
*/
protected $image;
protected $imageFile;
protected $watermarkFile;
protected $runtimeTextFile;
protected $runtimeWatermarkFile;
protected function setUp()
{
$this->imageFile = Yii::getAlias('@yiiunit/data/imagine/large') . '.jpg';
$this->watermarkFile = Yii::getAlias('@yiiunit/data/imagine/xparent') . '.gif';
$this->runtimeTextFile = Yii::getAlias('@yiiunit/runtime/image-text-test') . '.png';
$this->runtimeWatermarkFile = Yii::getAlias('@yiiunit/runtime/image-watermark-test') . '.png';
parent::setUp();
}
protected function tearDown()
{
@unlink($this->runtimeTextFile);
@unlink($this->runtimeWatermarkFile);
}
public function testText() {
if(!$this->isFontTestSupported()) {
$this->markTestSkipped('Skipping ImageGdTest Gd not installed');
}
$fontFile = Yii::getAlias('@yiiunit/data/imagine/GothamRnd-Light') . '.otf';
$img = $this->image->text($this->imageFile, 'Yii-2 Image', [
'font' => $fontFile,
'size' => 12,
'color' => '000'
]);
$img->save($this->runtimeTextFile);
$this->assertTrue(file_exists($this->runtimeTextFile));
}
public function testCrop()
{
$point = [20,20];
$img = $this->image->crop($this->imageFile, 100, 100, $point);
$this->assertEquals(100, $img->getSize()->getWidth());
$this->assertEquals(100, $img->getSize()->getHeight());
$point = new Point(20, 20);
$img = $this->image->crop($this->imageFile, 100, 100, $point);
$this->assertEquals(100, $img->getSize()->getWidth());
$this->assertEquals(100, $img->getSize()->getHeight());
}
public function testWatermark()
{
$img = $this->image->watermark($this->imageFile, $this->watermarkFile);
$img->save($this->runtimeWatermarkFile);
$this->assertTrue(file_exists($this->runtimeWatermarkFile));
}
public function testFrame()
{
$frameSize = 5;
$original = $this->image->getImagine()->open($this->imageFile);
$originalSize = $original->getSize();
$img = $this->image->frame($this->imageFile, $frameSize, '666', 0);
$size = $img->getSize();
$this->assertEquals($size->getWidth(), $originalSize->getWidth() + ($frameSize * 2));
}
public function testThumbnail()
{
$img = $this->image->thumbnail($this->imageFile, 120, 120);
$this->assertEquals(120, $img->getSize()->getWidth());
$this->assertEquals(120, $img->getSize()->getHeight());
}
/**
* @expectedException \yii\base\InvalidConfigException
*/
public function testShouldThrowExceptionOnDriverInvalidArgument() {
$this->image->setDriver('fake-driver');
}
/**
* @expectedException \InvalidArgumentException
*/
public function testShouldThrowExceptionOnCropInvalidArgument() {
$this->image->crop($this->imageFile, 100, 100, new \stdClass());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testShouldThrowExceptionOnWatermarkInvalidArgument() {
$this->image->watermark($this->imageFile, $this->watermarkFile, new \stdClass());
}
abstract protected function isFontTestSupported();
}
<?php
namespace yiiunit\extensions\imagine;
use yii\imagine\Image;
/**
* @group vendor
* @group imagine
*/
class ImageGdTest extends AbstractImageTest
{
protected function setUp()
{
if (!function_exists('gd_info')) {
$this->markTestSkipped('Skipping ImageGdTest, Gd not installed');
} else {
$this->image = new Image();
$this->image->setDriver(Image::DRIVER_GD2);
parent::setUp();
}
}
protected function isFontTestSupported()
{
$infos = gd_info();
return isset($infos['FreeType Support']) ? $infos['FreeType Support'] : false;
}
}
\ No newline at end of file
<?php
namespace yiiunit\extensions\imagine;
use yii\imagine\Image;
/**
* @group vendor
* @group imagine
*/
class ImageGmagickTest extends AbstractImageTest
{
protected function setUp()
{
if (!class_exists('Gmagick')) {
$this->markTestSkipped('Skipping ImageGmagickTest, Gmagick is not installed');
} else {
$this->image = new Image();
$this->image->setDriver(Image::DRIVER_GMAGICK);
parent::setUp();
}
}
protected function isFontTestSupported()
{
return true;
}
}
\ No newline at end of file
<?php
namespace yiiunit\extensions\imagine;
use yii\imagine\Image;
/**
* @group vendor
* @group imagine
*/
class ImageImagickTest extends AbstractImageTest
{
protected function setUp()
{
if (!class_exists('Imagick')) {
$this->markTestSkipped('Skipping ImageImagickTest, Imagick is not installed');
} else {
$this->image = new Image();
$this->image->setDriver(Image::DRIVER_IMAGICK);
parent::setUp();
}
}
protected function isFontTestSupported()
{
return true;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment