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

Fix statsSync format #121

Merged
merged 1 commit into from
Aug 27, 2021
Merged

Fix statsSync format #121

merged 1 commit into from
Aug 27, 2021

Conversation

ebeigarts
Copy link
Contributor

Image.statsSync doesn't work with svg because image-size returns type instead of format and getFullStats expects metadata.format.

EleventyImg Skipping SVG output for './src/images/sd-logo-horizontals-rgb.svg': received raster input. +0ms
getImageSize(src)
> { height: 32, width: 118, type: 'svg' }

Config:

function imageShortcode(src, alt, cls) {
  const Image = require("@11ty/eleventy-img")
  let options = {
    widths: [null],
    formats: ["avif", "webp", "png", "svg"],
    svgShortCircuit: true,
    urlPath: `${pathPrefix}/img/`,
    outputDir: 'public/img/',
  }
  Image(src, options)
  const metadata = Image.statsSync(src, options)
  const imageAttributes = {
    alt,
    class: cls,
    loading: "lazy",
    decoding: "async",
  }
  return Image.generateHTML(metadata, imageAttributes)
}

eleventyConfig.addNunjucksShortcode("image", imageShortcode)

image-size returns `type` instead of `format`
@zachleat zachleat merged commit 24d96cd into 11ty:master Aug 27, 2021
@zachleat
Copy link
Member

Thank you!

@zachleat zachleat added this to the v1.0.0 milestone Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants