-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Feature Request]: Include a CI check that ensures Oppia's images are fully compressed. #21274
Comments
I want to fix it. |
@souja450 Per the guidance at https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue, please provide an explanation of what your PR will do (with names of files you're changing, what you plan to change in each file, etc.). If it looks good, we can assign you to this issue. Please also follow the other instructions on that wiki page if you have not yet done so. Thanks! |
Hey @seanlip attached a PR, could you please review it once ? One more thing this PR isn't fix auto compression of image which I'll add soon. |
@Ashu463 Let me know when you have a complete solution, and I'll review it then. Thanks. |
I have fixed this in this PR. Have a look there. |
Hey @seanlip here is solution which I thought to apply ->
|
@Ashu463 I took a look, thanks. I think your general approach is fine but the image compression check should use the same mechanism as the solution you are recommending (trimage in this case), otherwise there's a risk that contributors will use that tool and still fail the check. Can you make the necessary updates? |
@seanlip I am just confused what you are trying to say but what I get is you want trimage to compress the exceeded images on which I'm working right now. The intial solution was made to just show my interest over the issue. |
Hey @seanlip is there any other tool available for compresing, as trimage causes an unknown error whose solution I hadn't found anywhere ? |
Have you tried searching for the error message? I did a search and got this as the very first result: https://stackoverflow.com/questions/69994530/qt-qpa-plugin-could-not-find-the-qt-platform-plugin-wayland |
Yeah I do try those but got another error as QSocketNotifier: Can only be used with threads started with QThread, whose available solutions are not working even. I think it'll take time to debug, will inform you if issue persists. |
Hey @seanlip with my research trimage uses a library GLIBC and trimage is not maintained properly to be compatible with GLIBC 2.39 latest version, and thus there were very less answers to help out there. |
Hey @seanlip sorry for the delay in reply but now my exams are over and will share updates soon. |
Hey @seanlip I will recommend to use imagemagick as it is very similar to trimage and supports almost 200+ image extensions, also this works fine with the script. |
@Ashu463 I don't have an issue with imagemagick if it works fine. In terms of the size check, we should compress losslessly as much as possible. The idea then is that if the same compression is run on any existing image in Oppia then it would compress to that same final size (the 1% is just an error tolerance). This way, we can detect whether an image hasn't been run through the compression pipeline yet. Does that make sense? |
@seanlip got it, will share you a demo soon. |
Hey @seanlip here is the demo, and the approach is :
Screencast.from.2024-12-17.21-44-02.mp4 |
@Ashu463 Can you link to documentation that confirms that the compression you're doing with both PIL and ImageMagick is lossless? I need to make sure that this is the case so that the compression doesn't result in sub-quality images. Thanks. |
Hey @seanlip there is no such official documentary where ImageMagick claimed to compress images losslessly, but here is link of some chat or FAQ opened by them officially where someone had discussed about its lossless nature. |
@Ashu463 Thanks. I think more research is needed. We need authoritative documentation that the methods you are using for this are lossless. |
@seanlip fine, will update you soon with much legit ones. |
Hey @seanlip following are my some observation while searching :
|
Thanks @Ashu463. So how should we proceed? Can you compare the performance here to e.g. trimage or other libraries so that we can compare the different options and make an informed decision? |
@seanlip Yeah sure I could compare it with various tools but how could I show that to you, attach directly ss or something else ? |
Hey @seanlip here is I think you need, I am not attaching any documentation link or ss but if you need then pls let me know once I'll attach it. Following features are the advantages or the reasons why should we choose ImageMagick over other tools:
But ImageMagick do have some loopholes listed as :
With these pros and cons, I would conclude that Imagemagick definitely have some issues but it can be totally fine to use it as cons could be neglected over its pros. |
@Ashu463 Are there no other tools to consider besides ImageMagick? It would be good to see a list of tools and their pros/cons, with links to supporting documentation if possible. I am not really sure about ImageMagick's "removing metadata only" issue. Usually we want to compress the actual image (not just its metadata) without reducing its quality. |
Hey @seanlip had you gone through it ? |
Yes, I've just taken a look, thanks for the ping. Note that you only need to consider JPEG, PNG and WEBP (don't worry about SVG). I think that including a table that demonstrates, for each (tool, filetype) pair, the (a) compression percentage and the (b) time needed for compression would be helpful (and that links to the resulting images). You can try using representative images that are already in the Oppia codebase. Also, I think it's OK to use different libraries for different file types if needed. Just note that all compression must be lossless. Could you please update the doc accordingly and ping this thread when you'd like a follow-up review? Thanks. |
Yeah sure, will update here soon as I am busy in issue#21294. |
Hey @seanlip it is quite impossible to collect exact data for compression percentage and time needed from official documentation, as these compression tools docs never talks about these thing. For these data we have to rely on some chats said somewhere which can't be declared official. Moreover Compression percentage could be find with the help of two sizes of image before and after the compression. And same for the time, so what should I do for making that table ? |
Just run the pipelines on some sample images and record that data. |
Hey could you also help me here #21568 ? |
Hey @seanlip I'd updated the doc with table consist of tool name, compression %age, and time while compression. |
@Ashu463 Thanks. Please provide "anyone can comment" access to your doc. Could you please also provide links, from the doc, to the initial and final images in each case, so that we can check the quality? I would also suggest you use a small and a large image for each case so that we can see how each of those is handled. Try to use images from the Oppia website/codebase where possible -- thanks. |
Hey @seanlip I'd updated doc as whatever you said, picked one small and one large image of .JPEG and .PNG extensions and detailed about them. Also there will be suprise for .webp extension. Moreover I attached original image and compressed image by various tools over doc. Note that all the image I used is from oppia's repository itself. |
Hey @seanlip had you gone through doc ? |
@Ashu463 Sorry for the late reply, I'm getting a lot of emails each day and it's hard to respond to them all. Thanks for the ping to look at this again. Based on your analysis, I think GraphicMagick is probably the way to go since the runtime is faster than optipng and the resulting images look reasonable. Does this give you enough information to proceed? We can do the compression for all jpg, png and webp images (not svg). Thanks! |
It's all fine @seanlip, Yeah I can proceed with GraphicMagick now for all except svg, Now it's the time to show you some demo which I will share soon. Please assign this to me now so that I can open PR as well. |
Is your feature request related to a problem? Please describe.
We have encountered issues in the past where, due to large image files being added to the Oppia repository, we are unable to deploy the code because the build is too large. On further examination, these issues occurred due to large binary images included in the code, and compressing the images fixed the issue.
In order for this to not recur, we would like to implement a CI check that fails and blocks a PR when images in the PR are not properly optimized.
Describe the solution (or solutions) you'd like
Implement a CI check that either scans all images in a PR (or scans all images in the codebase), and compresses them using a tool like trimage.
The check should print out the following data about each image: filename; original size; compressed size.
If the size of any image in the PR/codebase exceeds the compressed image's size by 1% or more, fail the CI check and note the image that failed. The error message should provide instructions to the developer about how to run trimage on the problematic images and replace them in their PR (or better still, upload the compressed images as an artifact so that the developer can download and replace them directly).
Describe alternatives you've considered and rejected
The 1% allowance is optional but gives a bit of leeway. It's fine to make that percentage smaller, but it probably shouldn't be 0% unless trimage behaves fully deterministically (I haven't investigated this though).
Additional context
No response
The text was updated successfully, but these errors were encountered: