Skip to content

Media: Set width and height for uploaded SVGs#22244

Merged
AndyButland merged 27 commits intoumbraco:mainfrom
enkelmedia:v17/feature/22114-svg-width-height
Mar 26, 2026
Merged

Media: Set width and height for uploaded SVGs#22244
AndyButland merged 27 commits intoumbraco:mainfrom
enkelmedia:v17/feature/22114-svg-width-height

Conversation

@enkelmedia
Copy link
Copy Markdown
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

If there's an existing issue for this PR then this fixes #22114

Description

Following this discussion #22114 I've added a draft PR here that implements support for setting width/height on uploaded SVGs.

This PR contains:

  • A migration that will add umbracoWidth and umbracoHeight to the umbracoMediaVectorGraphics media type if it exists.
  • A new interface + implementation for parsing uploaded SVGS (ISvgDimensionExtractor and SvgDimensionExtractor) including unit tests.
  • A NotificationHandler that will set the properties when a .svg file is uploaded.

@github-actions
Copy link
Copy Markdown

Hi there @enkelmedia, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Copy link
Copy Markdown
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @enkelmedia - it looks a good enhancement to me, but I found a few things comment on. Mostly nits/straightforward fixes, but there are some to consider around handling non-pixel values and ensuring we are prepared for new installs.

enkelmedia and others added 18 commits March 25, 2026 14:59
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
Co-authored-by: Andy Butland <abutland73@gmail.com>
@enkelmedia
Copy link
Copy Markdown
Contributor Author

enkelmedia commented Mar 25, 2026

Thanks for all the feedback @AndyButland!

I've adjusted everything according to your feedback:

  • Code style changes, if-statements
  • Tested migration re-run and when umbracoWidth & umbracoHeight already exists
  • Updated DatabaseDataCreator to add umbracoWidth & umbracoHeight for clean installs.
  • Removed the %,em,cm attribute parsing, falling back to viewbox.
  • Cleaned up int-parsing

Just this question left:

If you think I should do explicit check in AddDimensionsToSvg.cs to see if umbracoWidth/height already exists ✅ This has been solved.

@AndyButland AndyButland changed the title Width and Height for uploaded SVGs Media: Set width and height for uploaded SVGs Mar 26, 2026
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

This all looks good to me now @enkelmedia, and having tested out I see it working as expected. The migration completes and populates the properties on the media type, and saving an SVG populates the width and height values. A new install similarly creates the expected properties.

I made a few changes based on clean-up, extra tests, some tightening up of logic to account for edge cases. Please let me know if it looks good to you or if you see anything further for improvement. Otherwise we can merge this in.

@enkelmedia
Copy link
Copy Markdown
Contributor Author

Thank you very much for the polish @AndyButland!

Everything looks good to me! Feel free to merge 🎉

@AndyButland AndyButland merged commit a03fb9b into umbraco:main Mar 26, 2026
26 of 27 checks passed
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.

3 participants