-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Add Symfony Image Component #21820
Conversation
I just updated the description |
ffc201d
to
336c887
Compare
I'm not a fan of integrating it in Symfony as is. The Symfony BC policy would forbid adding any new feature in the component after the initial release, unless we mark all interfaces as internal, due to the current architecture. And marking them as internal would also remove the BC promise for consuming code. |
@stof The thing is that the original library has enough people to maintain it. I would not like to see it unmaintained. It's been stable for years, why would we want to change the internal behavior? I mean, we can do that in the coming months/years, benefiting from our processes and the power of the Symfony community. This is just a first step. Thanks @avalanche123 for making that possible. |
@fabpot you're welcome, happy to see Imagine finding a new home, thank you! |
I'm supporting this proposal. Two questions to start:
|
336c887
to
dcd13b3
Compare
Marking the whole component as experimental for 3.3 looks like a good compromise to me. |
4ee00c7
to
82598b6
Compare
I don't think we will change these fixtures often, meaning we will almost never store a new blob for them. |
Any interest in merging contao/imagine-svg too? |
While I'm not convinced moving standalone libs into Symfony is a good trend, I doubt I'll convince you not to do it, so I'd like to insist on one aspect which I think is important in terms of code design and quality: Please keep in mind it should work with very large images and that nothing should load the whole image in memory and do copies and so on. All gd/imagick transforms can be applied on files directly if done properly IIRC, and I'd like to avoid a repeat of php-imagine/Imagine#479 if possible :) Maybe generating large fixture files while running the test suite would be an idea, or running those tests with a very low memory limit to make sure any mistake is caught early? |
As Git LFS is not suitable for open-source projects, you can host fixtures on some CDN and have a phpunit listener that will download those fixtures on-demand with a sha256 checksum check. This solution allows to:
I already used a such setup for a photo application with 500MB of pictures without any issue. |
Please, let's keep things simple. Git LFS and CDN would only complicate things. The "problem" is quite limited and (probably) easy to solve:
Our biggest problems are:
|
@ausi that could be possible, but that'd require a license and copyright change. Would you agree on that? Anyway, I suggest to wait for this PR to be accepted and merged, then you could make a PR to add contao/imagine-svg if you'd agree to. |
@nicolas-grekas changing the copyright and license should be no problem. |
Can't we use the same approach like the old ICU component? A separate repository for the data, you already have Git so that shouldn't be a problem. |
e6d05fb
to
44c814e
Compare
Hi everybody, I think we're now ready, and I'm calling for reviews :)
I may have forgot something. Looking forward to read your comments. |
9765c31
to
d2e7f46
Compare
.github/imagick.sh
Outdated
|
||
if [ ! -e ./ImageMagick-$IMAGEMAGICK_VERSION ] | ||
then | ||
wget http://www.imagemagick.org/download/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz |
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.
I would use https
(they support it)
$save = 'image'.$format; | ||
$args = array(&$this->resource, $filename); | ||
|
||
// Preserve BC until version 1.0 |
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.
IMO, we don't need to keep the BC layers of Imagine 0.x here
$this->setExceptionHandler(); | ||
|
||
if (false === call_user_func_array($save, $args)) { | ||
throw new RuntimeException('Save operation failed'); |
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.
the error handler must be restored before this exception. I suggest using try/finally
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.
Please check the whole component for similar leaks of the internal error handler in case of exceptions
return in_array($format, $formats); | ||
} | ||
|
||
private function setExceptionHandler() |
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.
should be renamed, as it is setting the error handler, not the exception handler
}, E_WARNING | E_NOTICE); | ||
} | ||
|
||
private function resetExceptionHandler() |
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.
do we really need a private method here (badly named) ?
@@ -0,0 +1,3 @@ | |||
Symfony Image Component | |||
======================= | |||
|
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.
The readme is incomplete here. It should have the basic info we have in other components
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.
addressed
} | ||
|
||
if (!is_numeric($delta)) { | ||
throw \PHPUnit_Util_InvalidArgumentHelper::factory(2, 'numeric'); |
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.
this won't work on PHPUnit 6, as the non-namespaced class does not exist anymore
|
||
$canvas->save(__DIR__.'/../results/smiley.png'); | ||
|
||
$this->assertTrue(file_exists(__DIR__.'/../results/smiley.png')); |
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.
Use assertFileExists
use Symfony\Component\Image\Exception\RuntimeException; | ||
use Symfony\Component\Image\Tests\TestCase; | ||
|
||
class Issue59Test extends TestCase |
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.
Tests should be renamed, as referencing Imagine issue numbers does not make sense
->ellipse(new Point(125, 100), new Box(50, 50), $this->getColor('fff')) | ||
->ellipse(new Point(275, 100), new Box(50, 50), $this->getColor('fff'), true); | ||
|
||
$canvas->save(__DIR__.'/../results/smiley.png'); |
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.
you should either use a path outside the repo (in the system temp dir) or mark this folder as ignored.
d28942c
to
96451e7
Compare
96451e7
to
a80d5f0
Compare
I think I've addressed all your comments. I've added a BC layer with deprecation for all options (reolution-* => resolution_*, quality, filters, resampling-filter) |
If Symfony really wants to introduce an Image component, it'd be great if it uses libvips. PHP binding here: https://github.com/jcupitt/php-vips A wonderful library based on libvips in the Node.js world: https://github.com/lovell/sharp |
Note that we may want to work on the brittle aspects of the unit tests before introducing this component: the Travis CI tests break regularly as the various extensions mature due to slightly different result values as well as deprecated and/or removed methods/constants/etc. Can we do something to mitigate these issues before adding this to the Symfony test runtime? |
This component is a port of Bulat Shakirzyanov's Imagine library (https://github.com/avalanche123/Imagine) into Symfony.