sugarlabs / musicblocks

Music Blocks -- A musical microworld
https://musicblocks.sugarlabs.org/
GNU Affero General Public License v3.0
556 stars 756 forks source link

Incomplete Functionality: Image Format Detection #3533

Open gitgoap opened 8 months ago

gitgoap commented 8 months ago

Description

The current code within the pluginify function at line 173 suggests incomplete functionality for detecting image formats, specifically to distinguish between different formats such as SVG and PNG.

Expected Behavior

The enhancement of the pluginify function should include accurate image format detection, particularly for detecting PNG format. Currently, the code assumes SVG format for images, but this functionality is incomplete and lacks the ability to handle PNG or other formats.

Screenshots

Screenshot 2024-01-07 203656

Console log Errors:

N/A

Environment:

Checklist


Thank you for contributing to our project! We appreciate your help in improving it.

πŸ“š See contributing instructions.

πŸ™‹πŸΎπŸ™‹πŸΌ Questions: Community Matrix Server.


Mubashirshariq commented 8 months ago

@walterbender sir i think we can use imghdr module to detect the image type and base64 for decoding which will ensure proper conversion, what are you thoughts about it

gitgoap commented 8 months ago

previous PR for this issue Great initiative with the image format detection using imghdr!

Noticed a potential enhancement: the current code lacks error handling for scenarios where imghdr.what() might fail.

viditagrawal56 commented 8 months ago

@walterbender From what I can find about imghdr , the python version is indeed deprecated. I found an alternative for it though, some projects have replaced the use of imghdr library with filetype library. We could also implement something similar.

Take a look at this -> https://github.com/lektor/lektor/issues/653#issuecomment-495396031

What's your opinion?

walterbender commented 8 months ago

is the discussion you found about python only? we need a stable JS solution.

divyanash911 commented 8 months ago

Can we use the PIL library for the same?

viditagrawal56 commented 8 months ago

@walterbender

is the discussion you found about python only

Yes the discussion is about python only.

we need a stable JS solution.

I just assumed that as the file is written in python, I just needed to find an alternative to imghdr lib. But if a stable JS solution is required then from what I could find FileReader API is a good way to find the type of the file, the drawback being that FileReader API uses the Magic number-based file type detection which is not foolproof.

I also found that there's an npm package of imghdr which is not being actively maintained. See -> https://www.npmjs.com/package/imghdr?activeTab=readme