-
Notifications
You must be signed in to change notification settings - Fork 200
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
Fully supports progressive JPGS and Interlaced images for 3.x #394
Conversation
TODO:
|
@ADmad would you mind to take a look and tell me what you think? I'm not sure if introducing this new encoding strategy would be the best for this package. feedbacks are welcome :) |
Sorry I haven't had the time to look into this but could you please address the failing tests in the meantime. |
@ADmad I addressed all the issues that Github Actions was issuing. Before setting this ready for review, could you point me the best place where I could add the tests for the progressive/interlaced images I am introducing? |
@ADmad I added some comments to help the review process. Ideally, it would be good to add tests for the new option added to the image API. But I don't have idea what would be the best place to put it. |
@ADmad I applied the suggested changes and also add a new doc entry for the new option. I'm just not sure how to preview documentation locally, but I guess it is following the same convention used before. Also, do you have idea on how we could test this new feature? I just updated |
@ADmad friendly ping to check if you had time to review changes. |
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.
An issue with having the encoder as a separate step instead of a manipulation is that one cannot add manipulators to be run after the image is encoded. For e.g. there's this optimizer manipulator which needs to run after encoding.
/** | ||
* The manipulation params. | ||
*/ | ||
private $params; |
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.
private $params; | |
private array $params; |
* | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
private $encoder; |
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 can specify the type for all these properties and avoid the @var
tags.
$manager->create(100, 100)->encode(new MediaTypeEncoder('image/gif'))->toFilePointer() | ||
); | ||
|
||
if (function_exists('imagecreatefromwebp')) { |
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.
Shouldn't this function be always available for PHP 8.1+?
); | ||
} | ||
|
||
if (function_exists('imagecreatefromavif')) { |
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.
Shouldn't this function be always available for PHP 8.1+?
/** | ||
* @psalm-suppress ArgumentTypeCoercion | ||
*/ | ||
$this->assertInstanceOf('League\Glide\Api\Encode', $this->encoder); |
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->assertInstanceOf('League\Glide\Api\Encode', $this->encoder); | |
$this->assertInstanceOf(Encode::class, $this->encoder); |
with use
statement for it.
$this->assertSame('image/jpeg', $this->getMime($this->encoder->setParams(['fm' => 'jpg'])->run($this->jpg))); | ||
$this->assertSame('image/jpeg', $this->getMime($this->encoder->setParams(['fm' => 'jpg'])->run($this->png))); | ||
$this->assertSame('image/jpeg', $this->getMime($this->encoder->setParams(['fm' => 'jpg'])->run($this->gif))); | ||
$this->assertSame('image/jpeg', $this->getMime($this->encoder->setParams(['fm' => 'pjpg'])->run($this->jpg))); |
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 have a way to check if the image is actually interlaced?
|
||
The `interlaced` parameter controls whether an image is rendered in a progressive or interlaced format. This feature enhances the loading experience of images, making them appear gradually as they are downloaded, which can improve the user experience on slower connections. | ||
|
||
> Caution: for GIF/PNG, it can generate a sligher larger file size. |
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.
> Caution: for GIF/PNG, it can generate a sligher larger file size. | |
> Caution: for GIF/PNG, it can generate a slightly larger file size. |
- **JPG**: The `Interlaced` parameter applies a progressive scan to JPG images. | ||
- **PNG** and **GIF**: The `Interlaced` parameter enables interlacing for GIF/PNG images. | ||
|
||
> Note: Case `ext` is set to `.pjpg`, it will automatically generate a progressive JPG image, regardless of the `interlaced` parameter. |
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.
> Note: Case `ext` is set to `.pjpg`, it will automatically generate a progressive JPG image, regardless of the `interlaced` parameter. | |
> Note: In case the `fm` parameter is set to `.pjpg`, it will automatically generate a progressive JPG image, regardless of the `interlaced` parameter. |
Just wanted to check up on the progress of this pr: Are there any updates about the progression to merge this into 3.x? I would really like to see version 3 to be released but afaik the release depends on the merge of this pr... |
Hey @konnng-dev, just wanted to check up on this issue again. Are there more updates on this PR to allow it to be merged? 😅 |
Since @konnng-dev seems to be unavailable I'll try and finish this up myself. |
d3e4bcf
into
thephpleague:feat/progressive-interlaced
Thanks for giving proper attention @ADmad and my apologies for overpromising. I ended up delivering the project using this package for the client and moved on to a different projects. Which caused me to sidetrack and lost focus on delivering this one. I hope my updates helps this library to be better compatible with Intervention v3. |
@konnng-dev No apology needed, thank you for your contributions. |
The intent of this PR is to introduce support to generate progressive JPEGs or interlaced images.
Couple days ago, the author of Intervention provided support to accomplish that https://github.com/Intervention/image/releases/tag/3.6.0
With that, I did some adjustments on Glide API to get the desired support.
Highlights:
Encode
manipulator moved from the$manipulators
list, because it needs to be the last manipulator to run when generating the images.Encode
manipulator now returns aEncodedImage
. This change avoids to double encode image when generating it.Encode
also makes more use of Interventionenums
to encode the image properly.