Skip to content

Gatsby image sharp traced SVG does not respect forced aspect ratio #9204

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

Closed
nakedible opened this issue Oct 18, 2018 · 7 comments
Closed

Gatsby image sharp traced SVG does not respect forced aspect ratio #9204

nakedible opened this issue Oct 18, 2018 · 7 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@nakedible
Copy link
Contributor

Description

When using gatsby-image and gatsby-plugin-sharp to produce traced SVG images for image loading, and specifying both maxWidth and maxHeight for the resulting image, the traced SVG image is from the full (uncropped) source image, where as the actual generated image is cropped to aspect ratio with the crop location defined by cropFocus. The end result is very jarring where the traces do not match at all with the actual image when loaded.

Instead the traced SVG should match the cropped actual resulting image, meaning that the image should be cropped to correct aspect ratio first, and then traced.

Steps to reproduce

Following GraphQL query:

childImageSharp {
              fluid(
                maxWidth: 600
                maxHeight: 600
              ) {
                ...GatsbyImageSharpFluid_tracedSVG
              }
}

And usage:

<Img fluid={childImageSharp.fluid} />

Expected result

Traced SVG should match the image that is to be loaded.

Actual result

Traced SVG is from uncropped image, meaning all lines are at different places.

Environment

Cannot get gatsby info because of #8502.

@nakedible
Copy link
Contributor Author

Doing some additional testing, this seems to be broken in a few ways. The healOptions handler seems really weird, only converting some values from strings to integers, filling in hardcoded width even when both maxHeight and maxWidth are present. In addition to that, the fluid handler does a lot more processing for width and height and other things before passing on those things to resize (through the job queue). Even small changes in the image pipeline can change the cropFocus attention or entropy strategy result.

The only reasonable way that I can see this being fixed would be to first do the cropping and resizing to correct size in the job queue, and then trace the exact generated image without any resize or crop - which constitutes of somewhat of a rewrite of the current code.

@kakadiadarpan
Copy link
Contributor

@nakedible can you provide a reproduction repo for this? That would make it much easier to diagnose this issue.

As you are not able to provide the result of gatsby info --clipboard, can you share your package.json here?

@kakadiadarpan kakadiadarpan added status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Oct 23, 2018
@fk
Copy link
Contributor

fk commented Oct 23, 2018

I can confirm that traced SVGs do not match the cropped images. :(
Really sorry you're running into this @nakedible and thanks for opening up this issue! 🙏

@fk fk added type: bug An issue or pull request relating to a bug in Gatsby status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. and removed status: needs more info Needs triaging and reproducible examples or more information to be resolved status: needs reproduction This issue needs a simplified reproduction of the bug for further troubleshooting. labels Oct 23, 2018
@fk
Copy link
Contributor

fk commented Oct 23, 2018

Looked into this for a couple minutes, and want to clarify that this only is happening for fluid queries (that crop images), not for fixed ones.

@nakedible
Copy link
Contributor Author

No worries, it's nice to get actual bugs found and fixed. I added a comment about healOptions to the pull.

@gatsbot
Copy link

gatsbot bot commented Jan 25, 2019

Old issues will be closed after 30 days of inactivity. This issue has been quiet for 20 days and is being marked as stale. Reply here or add the label "not stale" to keep this issue open!

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 25, 2019
@gatsbot
Copy link

gatsbot bot commented Feb 5, 2019

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

Thanks again for being part of the Gatsby community!

@gatsbot gatsbot bot closed this as completed Feb 5, 2019
pieh pushed a commit that referenced this issue Apr 16, 2019
… forced aspect ratio (#9337)

Ref. #9204, not sure if this is the right way to go…

- split the [traced-svg](https://using-gatsby-image.gatsbyjs.org/traced-svg/) gallery into two—cropped and uncropped—to demonstrate the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants