Skip to content

Conversation

Kocal
Copy link
Member

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

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 ?

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

- $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
Member 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
Member 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
@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