Closed Orlandohub closed 5 years ago
Hi Orlando 👋
gatsby-plugin-sharp
/ gatsby-image
doesn't handle SVGs or GIFs. The fluid
query (in your case) creates multiple images from 0px to 1060px (+ bigger sizes for retina). That wouldn't make sense with SVGs as they're vector files and don't need different sizes - they can scale indefinitely without loss of quality.
If you want to use your svg you, e.g. could import / use it like:
import yourSVG from './logo_large.svg'
const Home = () => <><img src={yourSVG} /></>
I'm closing this issue as answered. If you have further questions, please reply.
@LekoArts Thank you so much for your quick response!
@LekoArts For fields that may have a combination of JPGs/PNGs and SVGs; it'd be super helpful if what was passed down to something like the original { src }
attribute could be that same image; even if no transformations happened on SVGs. Has that ever been discussed?
Had the same problem with a field that can be PNG, JPG and SVG. Solved it adding extension
and publicURL
in my query:
...
image {
childImageSharp {
fluid(maxWidth: 500, quality: 92) {
...GatsbyImageSharpFluid
}
}
extension
publicURL
}
...
And then, in the PreviewCompatibleImage, adding something like:
// svg support
if (!childImageSharp && extension === 'svg') {
return <img style={imageStyle} src={publicURL} alt={alt} />
}
@andresmrm Great idea, thanks!
Summary
When trying to load an SVG image this way:
I get
TypeError: Cannot read property 'childImageSharp' of null
If I try the exact same but with a
.jpg
or.png
image, it works, so the relative path must be correct. Any thing I should have in special consideration with SVG's?