-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Proposal for #46: Implementation of Image helper based on Imagine library #1669
Conversation
Conflicts: extensions/yii/jui/CHANGELOG.md
* origin/master: Update change log Add active id to options if input widget has a model fixes yiisoft#1550
* upstream: Fixed CSRF token masking issue. improved error message of calling invalid scope method. Fixed repo URL Fixes yiisoft#1650: Added Connection::pdoClass. code style fix. added changelog codestyle fix improved checkIntegrity method Modified extension guidlines fix sphinx command signature fixed bug with forgotten param, fixed behavior for one table integrity fixed sequence reset added postgresql features to reset seq/check integrity
* upstream: Fixed CSRF token masking issue. improved error message of calling invalid scope method. Fixed repo URL Fixes yiisoft#1650: Added Connection::pdoClass. code style fix. added changelog codestyle fix improved checkIntegrity method Modified extension guidlines fix sphinx command signature fixed bug with forgotten param, fixed behavior for one table integrity fixed sequence reset added postgresql features to reset seq/check integrity
Looks good to me. @yiisoft/core-developers What's your opinion? Do you plan to implement more commonly used methods? |
@qiangxue the ones included are the most common used. If @yiisoft/core-developers have any suggestions that cannot be easily handled with |
/** | ||
* @return array of available drivers. | ||
*/ | ||
public function getAvailableDrivers() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tonydspaniard About this method implementation. Why not just:
return [static::DRIVER_GD2, static::DRIVER_GMAGICK, static::DRIVER_IMAGICK];
For which goals you use excess/static variable ❓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@creocoder fast typing... fixing
Any other methods to implement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return ManipulatorInterface | ||
*/ | ||
public function watermark($filename, $watermarkFilename, Point $pos = null) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different methods interface looks inconstant: here you pass coordinates as an object, while in “crop()” you are using separated $startX, $startY.
Maybe “rotate()”. |
What about |
@qiangxue resize() is something very simple to do with access to
Same goes with rotation. Check results of the following code (frame it and then rotate -8 degrees):
|
private $_imagine; | ||
/** | ||
* @var string the driver to use. These can be: | ||
* - gd2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to provide constants in example or people will use strings directly.
Looks OK to me overall. |
* - imagick | ||
* - gmagick | ||
*/ | ||
private $_driver = "gd2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"gd" => 'gd'
How can I implement extension in my project. Can not find extension in extensions directory |
@kmergen This is not merget yet. |
* @param integer $y position on image to apply watermark. Defaults to null | ||
* @return ManipulatorInterface | ||
*/ | ||
public function watermark($filename, $watermarkFilename, $x = null, $y = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is better to pass coordinates as an array. Single argument will simplify the interface as well as cover possible pass of “Point” object:
public function watermark($filename, $watermarkFilename, $point = null)
{
if (is_array($point)) {
list($x, $y) = $point;
$point = new Point($x, $y);
} elseif ($point instanceof Point) {
// do nothing
}
}
Same strategy can be applied for all methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* upstream: (35 commits) Fixes yiisoft#1691: added “viewport” meta tag to layout views. Fixed the issue that query cache returns the same data for the same SQL but different query methods moved section subsection added typo [skip ci] docs about response Fixes yiisoft#1586: `QueryBuilder::buildLikeCondition()` will now escape special characters and use percentage characters by default docs improved csrf docs added Fixes yiisoft#1685: UrlManager::showScriptName should be set true for tests. Fixes yiisoft#1688: ActiveForm is creating duplicated messages in error summary change back the visibility of findTableNames to protected. Typo fix. Fixes yiisoft#1681: Added support for automatically adjusting the "for" attribute of label generated by `ActiveField::label()` Simplified tests. Fixes yiisoft#1631: Charset is now explicitly set to UTF-8 when serving JSON Fixed typo added html layout for mail component in basic app CS fixes. Merge branch 'debug_module_improvements' of github.com:Ragazzo/yii2 into Ragazzo-debug_module_improvements ...
merged 2df7d0a |
I just review the code. It seems to me the only configurable option is which driver to use. For this reason, how about we turn this into a static helper instead of an application component? The helper can automatically choose which driver to use based on the installed PHP extensions. |
Sounds good to me. We can have a static property for the driver that is null for autodetect and may be set explicitly. |
@cebe Which order for autodetection:
or
? |
Gmagick, Imagick, Gd2 according to performance and efficiency. |
Finished refactoring. |
@tonydspaniard The |
margin could be positive for inside frame or negative for outside frame. alpha should have no effect on outside frame then. For the text() method I think we should add a position parameter that can be a point or array as it is in the other methods. it is quite uncommon that the position will be default. |
rest of the code looks really cool to me :) |
I have refactored the text() method as you suggested. I like your suggestion about the frame margin. I don't know how to implement the inside frame though. @tonydspaniard Do you have any idea? |
Closes #46
Implements common used methods for Image manipulation:
Yii::$app->image->crop('/path/to/image.jpg', 200, 200, 720, 450);
Yii::$app->image->thumb('/path/to/image.jpg',120, 120);
Yii::$app->image->text('/path/to/image.jpg', 'Yii-2 Image', ['font' => 'path/to/font.otf', 'size' => 12, 'color' =>'000']);
Yii::$app->image->crop('/path/to/image.jpg', /path/to/watermark.jpg' );
Yii::$app->image->frame('/path/to/image.jpg', 5 );
It uses Imagine library. It also contains a method to access Imagine methods directly (ie when used for simple image manipulations):
Edit: This extension is on WIP, methods are proven to work, if accepted. Then will write the tests