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

get_image_metadata values for width and height are backwards for SVG images #1877

Closed
Jieiku opened this issue May 27, 2022 · 4 comments
Closed
Labels
bug done in pr Already done in a PR

Comments

@Jieiku
Copy link
Contributor

Jieiku commented May 27, 2022

Bug Report

Zola version: 0.15.3

It seems that get_image_metadata gets the width and height backwards? It may only be for svg images.

I was extending the imghover shortcode that I wrote, so that width and height are optional parameters, (since we can query this data with get_image_metadata)

You can see the result here: https://abridge.netlify.app/overview-images/#usage-same-path-1

and here is the repository: https://github.com/Jieiku/abridge

and here is the shortcode: https://github.com/Jieiku/abridge/blob/master/templates/shortcodes/imghover.html

      {%- set metafile = page.path ~ path ~ sourcepath %}
      {%- set meta = get_image_metadata(path=metafile) %}
      {%- set padding = meta.height / meta.width * p %}
      /* height={{meta.height}} width={{meta.width}} (THIS IS BACKWARDS!?) */

The image in question is 600 width and 400 height, but get_image_metadata() report it the other way around.

2022-05-27_00-55-45

@Jieiku Jieiku changed the title get_image_metadata values for width and height are backwards. get_image_metadata values for width and height are backwards for SVG images May 27, 2022
@Keats
Copy link
Collaborator

Keats commented May 27, 2022

yep it looks reversed in the code

@Keats Keats added the bug label May 27, 2022
@mre
Copy link
Contributor

mre commented May 27, 2022

Sorry about that; quite embarrassing. I can send a PR to fix it later today. Alternatively you can fix it by swapping w and h at the end of this line:

.map(|(h, w)| ImageMetaResponse::new_svg(h as u32, w as u32))

There's also a typo in "Unfortunately" below that line that we could fix as well.

@Jieiku
Copy link
Contributor Author

Jieiku commented May 28, 2022

@mre is swapping the w and the h the proper way of fixing this, or just a workaround that I could do?

If that is the proper way of fixing it then I can do the pull request for you.

(love rust! but still a newbie at using it)

@mre
Copy link
Contributor

mre commented May 28, 2022

Yes, please go ahead. It's the proper way to do it in my opinion because my SVG Metadata crate returns the dimensions in swapped order and I don't want to change that because of other use cases. Perhaps you'd like to add a comment about that fact as well so people don't confuse it for a typo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug done in pr Already done in a PR
Projects
None yet
Development

No branches or pull requests

3 participants