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

Feature Request #1

Closed
andimg93 opened this issue Feb 23, 2021 · 8 comments
Closed

Feature Request #1

andimg93 opened this issue Feb 23, 2021 · 8 comments

Comments

@andimg93
Copy link

Can you add a optimization possibility like https://packagist.org/packages/spatie/image-optimizer

The main problem for every image library is the part with animated gifs - well, yours support animated gifs BUT have no possiblity to optimize the image itself :(.

@andimg93
Copy link
Author

There was a great but unsupported image library: https://packagist.org/packages/kosinix/grafika

@ve3
Copy link
Contributor

ve3 commented Feb 23, 2021

This class using Imagick to manipulate animated GIF, you can call to Imagick property on my Imagick class to access the original PHP Imagick class and use any methods that PHP Imagick available.

Or once you have done image manipulation with this class, you can use another image library that is able to optimize to do it.

@ve3
Copy link
Contributor

ve3 commented Feb 24, 2021

There was a great but unsupported image library: https://packagist.org/packages/kosinix/grafika

I don't understand what "unsupported image library" is in your meaning.
From what I see, the Grafika class is full featured image manipulation and have even more features than my class.

@andimg93
Copy link
Author

It makes no sense to use a library for the optimization, because currently none exists that can handle animated gifs. For example, you adjust the size of an animated gif file with the library from you, and then lose the animation through "optimization"?

Grafika is still no longer maintained. Means for over 5 years there was nothing more adjusted there. It has bugs for which even pull requests are already open, but are not merged and also in terms of code maintenance towards PHP 8 and further nothing will happen anymore with Grafika. That's what I mean by unsupported.

@ve3
Copy link
Contributor

ve3 commented Feb 24, 2021

This class maybe not working on PHP 8 because PHP Imagick don't publish the version for Windows yet. I don't have PHP Imagick extension for PHP 8 on Windows to work with. (Reference 1 2)

I'm not sure does Imagick::optimizeImageLayers() would help?

$Image = new \Rundiz\Image\Drivers\Imagick('/path/to/source-image.gif');
$Image->resize(900, 600);

// access Imagick class and then optimize layers
$Imagick = $Image->Imagick;
$Imagick->optimizeImageLayers();

$Image->save('/path/to/new-file-name.gif');

https://www.php.net/manual/en/imagick.optimizeimagelayers.php

Compares each image the GIF disposed forms of the previous image in the sequence. From this it attempts to select the smallest cropped image to replace each frame, while preserving the results of the animation.

I'm not tested with the code above but I hope that the result will be better compare to the code below.

$Image = new \Rundiz\Image\Drivers\Imagick('/path/to/source-image.gif');
$Image->resize(900, 600);
$Image->save('/path/to/new-file-name.gif');

Now, I understand that you want animated GIF optimization but that seems to very hard for me because If I can do that, I should be able to make resize animated GIF with GD too.
Work with animated GIF is frame by frame and that is seems beyond my ability.

@andimg93
Copy link
Author

Such a solution only with a little more optimization I have already written, but unfortunately there is currently a problem with imagick and the installation via pecl at PHP8+.
Therefore I can this currently not test, except on my server - There it seems to go. On my Mac I can not get it installed. There is also an issue ticket for that: Imagick/imagick#331

@ve3
Copy link
Contributor

ve3 commented Feb 24, 2021

Yes, I've just tested and it is the same or did not much help.

Sorry, animated GIF optimization is over my limit, I'm not that smart to create something awesome like that.

@andimg93
Copy link
Author

You set your own limits - There is only in fact one limit and that is time.

But all good 👍🏼

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

No branches or pull requests

2 participants