-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Render mobile images to standard size #2043
Conversation
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.
@audiodude The image is retrieved from the right place but I don't understand why you change the resolution. It's not our role to change the resolution.
It's seems you think the size given is wrong, but I'm not sure about the standardsyou refer too. I also don't understand hoe 140px width could be the right width!
Sorry, I guess I was confused about the requirements. If you look at the images retrieved from the sample endpoint, which I included in the test, you see that the first has
So the
Since I read in the reports that 640px was "too big/wide", I thought I had to resize the images. 140px was just an arbitrary value I chose. |
@audiodude Key approach (to see if we are doing good is) IMHO is to compare to what we get currently with the That said, I have still a concern that the size given in |
Yes looking at the HTML of https://bm.wikipedia.org/wiki/Bamak%C9%94 I see:
Which matches the wikicode:
Which has a width of 250, and that's what we see in So maybe the solution is to just set the |
If you read the issue (here and on Phabricator) this has been clearly what I requested... and what I expected this PR to do... But it we do only this we will:
I wonder how bad would these 3 points above be... and how important/urgent is this to fix. My (bad) feeling is that it is urgent and we need to either
What do you think? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2043 +/- ##
==========================================
+ Coverage 74.72% 74.73% +0.01%
==========================================
Files 41 41
Lines 3141 3143 +2
Branches 688 689 +1
==========================================
+ Hits 2347 2349 +2
Misses 675 675
Partials 119 119 ☔ View full report in Codecov by Sentry. |
I think there is a confusion about what "mobile-friendly" means. It seems the Mediawiki software is using 640px and 320px images as "mobile-friendly" because they will take up the full width of the phone, which arguably looks better when you're scrolling an article in vertical format. I don't think there is any concept here, in the original software, that "mobile-friendly" means "saving bandwidth". I don't think using the So I think using the original page image will:
As far as recomputing the cache of pictures, that is definitely a side effect, but seems necessary. I just don't think WMF or the Mediawiki maintainers have any more idea what a "mobile-friendly" size is than we do, or at least they have a very different definition of it. That's why I just guessed 140px. |
Yes, the "mobile-html" new API we use is conceived for The Wikipedia mobile app. I believe the mobile app does on the fly image resising (probably depending of the device screen resolution).
You might be right, but reference should be current generated ZIM files, which use an other API. That should be actually really easy to do.
Yes, at least their definition of "mobile-friendly" has significantly evolved between the "mobile-section" API and the "mobile-html". To me "mobile-friendly" means "smaller than desktop", somlike it is currently with the "mobile section" API. |
So do I just compare https://download.kiwix.org/zim/wikipedia/wikipedia_bm_all_maxi_2024-06.zim with a new ZIM that I make from scratch using the updated code? Is there a way to see the params that were used to make that ZIM? I don't see a recipe on https://farm.zimit.kiwix.org/recipes probably because I don't have permssions? |
Yes
https://farm.openzim.org/recipes/wikipedia_bm_all Important to consider is the --webp option. |
Looks like the files are around the same, even with my changes to the image src: Created with my modified version of mwoffliner:
File from https://download.kiwix.org/zim/wikipedia/wikipedia_bm_all_maxi_2024-06.zim
|
Wait, do I have to modify a setting to force the mobile renderer? |
@audiodude |
Here is the command I used:
And here is the resulting file size:
So no significant impact on file size using the Mobile Renderer with getting the image src from |
I've updated the code, PTAL |
@audiodude Code LGTM, but CI is red. I will rebase. |
It looks like the tests are flaky, one of them is timing out sometimes:
|
|
This failure might be an actual bug because it's failing zimcheck for a MobileRenderer scrape. EDIT: Just checked the generated ZIM and the images do appear to be broken |
Looks like several of the images in the BMW article don't have
I guess we have to fall back to |
It looks like in the mobile API source code, that if the image didn't get resized, it doesn't have a https://github.com/wikimedia/mediawiki-services-mobileapps/blob/master/lib/thumbnail.js#L96 |
I guess this PR should be patched then!? |
Yes just updated. Tests pass locally. |
Force pushed to consolidate commits, PTAL |
Fixes #1925
In https://phabricator.wikimedia.org/T349972 a solution was given to img
data-src
attributes hardcoding images that are too big. This was the provision of an attributedata-data-file-original-src
which has the original src size of the image. By hacking this URL, we are able to provide images that are any size we want, in this case 140px is chosen arbitrarily.Note the use of the
WikimediaMobileRenderer.INTERNAL
object in this PR. This is to provide test access to methods that are, and should remain private. Here, we only want to test the image transformations of the renderer with a fake document. The production implementation usesthis.INTERNAL.convertLazyLoadToImages
to reference the private method, and we do the same in the test. This is the pattern that we have agreed upon in our Typescript codebase at YouTube and I think it works fairly well, though it is a bit ugly. The benefits are clear though from looking at the unit test provided with this PR. It is short and concise and fast, tests only the method being changed, and doesn't require a network connection or setting up a long chain of mwoffliner configs and objects.