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

[LazyImage] Abstract image content fetching #1781

Merged
merged 1 commit into from Apr 26, 2024
Merged

Conversation

Kocal
Copy link
Contributor

@Kocal Kocal commented Apr 25, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #1773
License MIT

Hi,

This PR is a proposal for #1773, logic to fetch content image is now customizable thanks to closure, meaning that an end-user can use whatever solution he wants to fetch the image content (HttpClient, Flysystem, ...).

I'm not 100% about the Closure::fromCallable(new Reference($config['fetch_image_content'])) tho

@carsonbot carsonbot added Feature New Feature LazyImage Status: Needs Review Needs to be reviewed labels Apr 25, 2024
@Kocal Kocal force-pushed the feat/GH-1773 branch 3 times, most recently from 9b3c320 to 0a0d8fd Compare April 25, 2024 07:54
@@ -74,8 +78,10 @@ private function doEncode(string $filename, int $encodingWidth = 75, int $encodi

private function generatePixels(string $filename, int $encodingWidth, int $encodingHeight): array
{
$imageContent = ($this->fetchImageContent)($filename);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just a quick check on the result ?

src/LazyImage/src/BlurHash/BlurHash.php Outdated Show resolved Hide resolved
src/LazyImage/src/BlurHash/FetchImageContent.php Outdated Show resolved Hide resolved
@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Apr 25, 2024
@smnandre
Copy link
Collaborator

- $this->fetchImageContent ??= fn (string $filename) => file_get_contents($filename);
+ $this->fetchImageContent ??= file_get_contents(...);

@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Apr 25, 2024
Comment on lines +49 to +53
->setArguments([
new Reference('lazy_image.image_manager', ContainerInterface::NULL_ON_INVALID_REFERENCE),
null, // $cache
null, // $fetchImageContent
])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like I can't set the 3rd argument if the 2nd argument has not been set, which can be the case if we have no cache configured, that's why I've changed to ->setArguments

@Kocal
Copy link
Contributor Author

Kocal commented Apr 25, 2024

Reviews have been applied, thanks :)

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Apr 25, 2024
@kbond
Copy link
Member

kbond commented Apr 26, 2024

Thank you Hugo.

@kbond kbond merged commit bfc3ab3 into symfony:2.x Apr 26, 2024
37 of 38 checks passed
@Kocal Kocal deleted the feat/GH-1773 branch April 26, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature LazyImage Status: Reviewed Has been reviewed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[LazyImage] Usage of file_get_contents for external images
4 participants