Ability to use original svg dimensions for height/width when used as image

Created on 25 September 2023, about 1 year ago
Updated 24 April 2024, 8 months ago

Problem/Motivation

Image tags seems beneficial to include height and width in general. Some reasons laid out here.

It would be nice to be able to use the dimensions of the SVG versus having to set hard height/widths. Specially in cases like logos where different size ratio svgs are supplied.

This could be a checkbox "Use uploaded svg height and width"

Or possibly calculate the ratio of the other value if you set one of the height/width. Like if the width was set to 400px, then in the output the height attribute would be the correct calculated height from the original SVGs image ratio.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs review

Version

2.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States madhaze

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @madhaze
  • πŸ‡ΊπŸ‡¦Ukraine dunot
  • Status changed to Needs work 11 months ago
  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    Please fix trailing spaces.

    What impact will this patch have on existing fields that have not been configured this way? If there is any chance this could cause regressions for existing users, then the approach will need to be implemented with a new optional checkbox, as mentioned in the issue summary.

  • πŸ‡ͺπŸ‡¨Ecuador jwilson3
    +++ b/web/modules/contrib/svg_image_field/src/Plugin/Field/FieldFormatter/SvgImageFieldFormatter.php
    @@ -258,6 +258,32 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
    +          $attributes = ['width'=>$width, 'height'=>$height];
    

    Might make sense to cast to an int (and optionally be sanitized) in one single place, before being sent to the Attributes array.

  • πŸ‡ΊπŸ‡¦Ukraine Vadym.Tseiko

    Vadym.Tseiko β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡¦Ukraine Vadym.Tseiko

    Re-roll patch #2. Fix phpcs.

  • Status changed to Needs review 8 months ago
  • Status changed to Needs work 8 months ago
  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    Code changes are okay, but marking NW to think through and address the second question on #3.

  • πŸ‡ΊπŸ‡¦Ukraine Vadym.Tseiko

    Hi @jwilson3, I thought that in comment #3 you meant the checkbox in formatted settings. When I re-rolled the patch I added to the formatter settings checkbox, labeled as 'Uploaded dimensions', if such enabled - then this code fires.

  • Status changed to Needs review 8 months ago
  • πŸ‡ΊπŸ‡¦Ukraine Vadym.Tseiko

    Set to Needs review to get clarification, what further needs to be done.

  • πŸ‡ͺπŸ‡¨Ecuador jwilson3

    You're totally right. My apologies. I was rushing through my issue queue reviews and didn't connect the dots even though I was looking right at it. πŸ€¦β€β™‚οΈ

    Leaving in needs review because it needs to be manually tested, with screenshots, etc. Can't guarantee I can get to this level of testing at the moment, so I'm happy to have help from anyone else following this issue.

Production build 0.71.5 2024