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

Fully supports progressive JPGS and Interlaced images for 3.x #394

Merged
merged 16 commits into from
Oct 27, 2024

Conversation

konnng-dev
Copy link

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 a EncodedImage. This change avoids to double encode image when generating it.
  • Encode also makes more use of Intervention enums to encode the image properly.
  • interlace parameter also was added to create progressive JPEGs or interlaced PNGs or GIFs.

@konnng-dev
Copy link
Author

konnng-dev commented Apr 22, 2024

TODO:

  • work on tests to check for progressive / interlaced images.
  • fix code formatting issues

@konnng-dev
Copy link
Author

@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 :)

@ADmad
Copy link
Collaborator

ADmad commented Apr 27, 2024

Sorry I haven't had the time to look into this but could you please address the failing tests in the meantime.

@ADmad ADmad mentioned this pull request Apr 27, 2024
@konnng-dev
Copy link
Author

konnng-dev commented May 9, 2024

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

src/Manipulators/Encode.php Show resolved Hide resolved
src/Manipulators/Encode.php Show resolved Hide resolved
src/ServerFactory.php Show resolved Hide resolved
src/Manipulators/Encode.php Show resolved Hide resolved
src/Api/Api.php Outdated Show resolved Hide resolved
@konnng-dev konnng-dev marked this pull request as ready for review May 20, 2024 13:03
@konnng-dev
Copy link
Author

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

src/Manipulators/Encode.php Show resolved Hide resolved
src/Manipulators/Encode.php Show resolved Hide resolved
src/Manipulators/Encode.php Show resolved Hide resolved
src/Api/Api.php Outdated Show resolved Hide resolved
@konnng-dev
Copy link
Author

@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 EncodeTest to comply with the recent changes, but I didn't have idea on how test that.

@konnng-dev konnng-dev requested a review from ADmad June 3, 2024 18:08
@konnng-dev
Copy link
Author

@ADmad friendly ping to check if you had time to review changes.

Copy link
Collaborator

@ADmad ADmad left a 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private $params;
private array $params;

*
* @psalm-suppress PropertyNotSetInConstructor
*/
private $encoder;
Copy link
Collaborator

@ADmad ADmad Jun 25, 2024

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')) {
Copy link
Collaborator

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')) {
Copy link
Collaborator

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

@ADmad ADmad Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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)));
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> 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.

@C2H6-383
Copy link

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

@konnng-dev
Copy link
Author

konnng-dev commented Sep 23, 2024

@C2H6-383 I ended up forgetting to push the asked changes to this PR. I appreciate the reminder.

I will try to address it this week so @ADmad can reviiew it.

@C2H6-383
Copy link

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? 😅

@ADmad ADmad changed the base branch from 3.x to feat/progressive-interlaced October 27, 2024 05:41
@ADmad
Copy link
Collaborator

ADmad commented Oct 27, 2024

Since @konnng-dev seems to be unavailable I'll try and finish this up myself.

@ADmad ADmad merged commit d3e4bcf into thephpleague:feat/progressive-interlaced Oct 27, 2024
7 checks passed
@konnng-dev
Copy link
Author

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.

@ADmad
Copy link
Collaborator

ADmad commented Oct 27, 2024

@konnng-dev No apology needed, thank you for your contributions.

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

Successfully merging this pull request may close these issues.

3 participants