Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

avalanche123
Copy link
Contributor

@avalanche123 avalanche123 commented Mar 1, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT
Doc PR See https://github.com/romainneutron/symfony-docs/tree/symfony-image-component

This component is a port of Bulat Shakirzyanov's Imagine library (https://github.com/avalanche123/Imagine) into Symfony.

@romainneutron
Copy link
Contributor

I just updated the description

@stof
Copy link
Member

stof commented Mar 1, 2017

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.

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

@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.

@avalanche123
Copy link
Contributor Author

@fabpot you're welcome, happy to see Imagine finding a new home, thank you!

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 1, 2017

I'm supporting this proposal. Two questions to start:

@fabpot
Copy link
Member

fabpot commented Mar 1, 2017

Marking the whole component as experimental for 3.3 looks like a good compromise to me.

@romainneutron romainneutron force-pushed the image-component branch 3 times, most recently from 4ee00c7 to 82598b6 Compare March 1, 2017 17:52
@stof
Copy link
Member

stof commented Mar 1, 2017

should we move the image fixtures to git LFS to not make the SF git history grow too much? (maybe a bad idea)

I don't think we will change these fixtures often, meaning we will almost never store a new blob for them.
However, we should exclude them from the archive download, to avoid having every Symfony user downloading them for nothing when using composer.

@ausi
Copy link
Contributor

ausi commented Mar 1, 2017

Any interest in merging contao/imagine-svg too?
I’m one of its maintainers.

@Seldaek
Copy link
Member

Seldaek commented Mar 1, 2017

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?

@andrerom
Copy link
Contributor

andrerom commented Mar 2, 2017

Would also like to see the above from @Seldaek being solved before this is stable (or even merged), a customer had this exact issue on a certain .sh platform, so I guess SensioCloud would have same issue @fabpot.

@lsmith77 lsmith77 mentioned this pull request Mar 2, 2017
9 tasks
@fbourigault
Copy link
Contributor

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:

  • save space in the main git repository.
  • allow use of very large images in tests.
  • allows you to enable caching on travis-ci.
  • allows to run tests against a large set of images.
  • is probably future-proof depending on which features would be added to the Image component.

I already used a such setup for a photo application with 500MB of pictures without any issue.

@javiereguiluz
Copy link
Member

Please, let's keep things simple. Git LFS and CDN would only complicate things. The "problem" is quite limited and (probably) easy to solve:

  • Tests/ is just 3,617,110 bytes
  • Resources/ is 9,241,014 bytes ... and you can't move this to Git LFS or a CDN

Our biggest problems are:

  • Resources\Adobe\CMYK\ files are massive! Do we need all of them?
  • Resources\Adobe\Profile Information.pdf is 444 KB. Do we need it?
  • Tests\Fixtures\cat.gif is 1 MB. Please, create a different GIF file.
  • Tests\Fixtures\pixel-CMYK.jpg is 744 KB. Can we replace it with a smaller image?
  • Tests\Fixtures\font\Arial.ttf is 773 KB. Can we replace it with a smaller and free font?

@nicolas-grekas
Copy link
Member

@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.

@ausi
Copy link
Contributor

ausi commented Mar 2, 2017

@nicolas-grekas changing the copyright and license should be no problem.
OK, then I wait until this PR gets merged.

@sstok
Copy link
Contributor

sstok commented Mar 2, 2017

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.

@romainneutron romainneutron force-pushed the image-component branch 6 times, most recently from e6d05fb to 44c814e Compare March 27, 2017 18:12
@romainneutron
Copy link
Contributor

Hi everybody,

I think we're now ready, and I'm calling for reviews :)
I've addressed the issues you pointed

  • moved the large fixtures to a dedicated repo
  • removed unnecessary ICC profiles
  • fixed the test suite (it should be alright now, no Image tests are failing)
  • I've pushed a doc branch mentioned in the PR header that contain a commit of the Imagine documentation adapted to Symfony docs. It definitely needs some work, but I'm pretty sure it would help any doc writer.
  • The whole component is marked as EXPERIMENTAL

I may have forgot something. Looking forward to read your comments.

@romainneutron romainneutron force-pushed the image-component branch 2 times, most recently from 9765c31 to d2e7f46 Compare March 28, 2017 07:11

if [ ! -e ./ImageMagick-$IMAGEMAGICK_VERSION ]
then
wget http://www.imagemagick.org/download/releases/ImageMagick-$IMAGEMAGICK_VERSION.tar.xz
Copy link
Member

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
Copy link
Member

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');
Copy link
Member

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

Copy link
Member

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()
Copy link
Member

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()
Copy link
Member

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
=======================

Copy link
Member

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

Copy link
Contributor

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');
Copy link
Member

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'));
Copy link
Member

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
Copy link
Member

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');
Copy link
Member

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.

@romainneutron romainneutron force-pushed the image-component branch 5 times, most recently from d28942c to 96451e7 Compare March 28, 2017 09:45
@romainneutron
Copy link
Contributor

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)

@teohhanhui
Copy link
Contributor

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

@nicolas-grekas nicolas-grekas modified the milestones: 3.3, 3.4 Apr 11, 2017
@robfrawley
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet