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

Add minimal support for SVG conversion and probing #181

Merged
merged 2 commits into from
Jul 30, 2024
Merged

Conversation

benoit74
Copy link
Collaborator

@benoit74 benoit74 commented Jul 11, 2024

Fix #113

Changes:

  • add a new convert_svg2png function to convert SVG to PNG
    • this does not reuse the existing convert_image API for three reasons. First it would make the code of convert_image more complex since we would have to first probe for image format to know if it is SVG (this is for now handled internally in PIL library, but does not work for SVG). Second because the conversion is almost always requiring to pass output width/height and these are different parameters for CairoSVG than for PIL, so the "user" already need to know that he is converting a SVG. Third because current need (convert SVG icon of websites in warc2zim) is only focused on conversion to PNG while convert_image is far more generic ; and CairoSVG does not have a generic conversion function, only conversion to a given format.
  • add support for probing SVG images
    • this is not handled by PIL, so we fallback to use libmagic since this library is already used in scraperlib and probably the most reliable/standard way to detect an SVG

Nota: #178 must be reviewed and merged first, these changes are based on this other PR

@benoit74 benoit74 self-assigned this Jul 11, 2024
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1eddabc) to head (c8e2a08).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           32        32           
  Lines         1452      1501   +49     
  Branches       251       262   +11     
=========================================
+ Hits          1452      1501   +49     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benoit74 benoit74 marked this pull request as ready for review July 11, 2024 08:48
@benoit74 benoit74 requested a review from rgaudin July 11, 2024 08:48
@rgaudin rgaudin changed the base branch from main to v4_breaking_changes July 26, 2024 11:43
Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

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

LGTM ; see my remark inline

src/zimscraperlib/image/conversion.py Show resolved Hide resolved
@benoit74 benoit74 force-pushed the v4_breaking_changes branch from 75eed4e to 2d2c547 Compare July 30, 2024 09:30
Base automatically changed from v4_breaking_changes to main July 30, 2024 09:32
@benoit74 benoit74 merged commit 6eb77a5 into main Jul 30, 2024
8 checks passed
@benoit74 benoit74 deleted the svg_support branch July 30, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for SVG conversion (e.g. to convert favicon) and confirm probing is OK
2 participants