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

Refactor image fetching #1190

Merged
merged 15 commits into from
Sep 14, 2020
Merged

Refactor image fetching #1190

merged 15 commits into from
Sep 14, 2020

Conversation

jtojnar
Copy link
Member

@jtojnar jtojnar commented May 4, 2020

Avoid repeating requests and clean up the old spaghetti.

Customization changes

To allow distinguishing between an icon coming from the feed item and one from the feed itself, we added a new optional getSourceIcon() method. When the getIcon() method returns null for an item or the item icon cannot be fetched, the source icon will be used as a fallback.

Both getSourceIcon() and getIcon() can return null now when an icon is not available.

@jtojnar jtojnar added this to the 2.19 milestone May 4, 2020
@jtojnar jtojnar force-pushed the img-refactor branch 3 times, most recently from 2ebc3cf to e187305 Compare May 9, 2020 21:17
@jtojnar jtojnar marked this pull request as draft May 9, 2020 21:18
@jtojnar jtojnar force-pushed the img-refactor branch 5 times, most recently from 213e5e2 to 91508f8 Compare September 12, 2020 22:56
@jtojnar jtojnar marked this pull request as ready for review September 12, 2020 22:58
if (0.8 < $aspectRatio && $aspectRatio < 1.3) {
$this->logger->debug('icon: using feed logo: ' . $faviconUrl);

return $faviconUrl;
Copy link
Member Author

@jtojnar jtojnar Sep 13, 2020

Choose a reason for hiding this comment

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

Eventually, we will want to return the blob here as well so that it does not have to be downloaded again but we have already decreased the number of downloads a lot and I do not want to delay this any longer.

Thanks Psalm for noticing. Weird that this has ever worked.

It was broken for five years: #639
No need to pass the item through.
No weird pass-by-reference any more.
To allow distinguishing between an icon coming from the feed item and one from the feed itself,
we added a new optional getSourceIcon() method. When the getIcon() method returns null for an item
or the item icon cannot be fetched, the source icon will be used as a fallback.

Both getSourceIcon() and getIcon() can return null now, if an icon is not available.
Only when both width and height are supplied and best fit.
If the image has no dimensions, it can hardly be resized.
We need the blob for content type detection so rather than downloading it twice, let's pass it to loadImage directly.
When SVG element was embedded in a HTML document, it was detected as SVG image instead of a HTML page, causing issues for favicon fetching.

Fixes: #1191
Some sites like golem.de use rectangular logos in feeds, which are unsuitable for feed icon.
Let's fall back to favicon instead.

Fixes: #1183
Reddit for some reason returns a JSON string "{}"
when trying to fetch `message/inbox`, which causes the ItemsIterator to freak out
and loop without an end.
@jtojnar jtojnar merged commit 2eac971 into master Sep 14, 2020
@jtojnar jtojnar deleted the img-refactor branch September 17, 2020 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant