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

Astro transformer format #110

Open
jlarmstrongiv opened this issue Dec 14, 2023 · 5 comments
Open

Astro transformer format #110

jlarmstrongiv opened this issue Dec 14, 2023 · 5 comments

Comments

@jlarmstrongiv
Copy link
Contributor

I may be misunderstanding how the transformers or Astro components work, but I’m not sure how to set webp as the format. The url param f=webp doesn’t work, and I can’t seem to get the <Source /> component to work either (maybe I’m setting type="image/webp" incorrectly?). Anyway, tips to get the webp format working are much appreciated.

The <Image /> component works great otherwise (once the typing is fixed)

@jlarmstrongiv
Copy link
Contributor Author

@ascorbic do you have any suggestions for where the url parameter isn’t getting passed correctly in https://github.com/ascorbic/unpic/blob/main/src/transformers/astro.ts ?

@ascorbic
Copy link
Owner

ascorbic commented Jan 5, 2024

Is it adding the param to the URL? Have you tried manually opening the image and changing the param? Are you able to get it to generate the right format?

@jlarmstrongiv
Copy link
Contributor Author

jlarmstrongiv commented Jan 7, 2024

I have confirmed that the Astro _image endpoint can generate other image formats, like webp
After more investigation, it seems

Setting the format on the image component fails when trying to add the param to the URL

        <UnpicAstroImage
          src="/static/assets/images/owl.jpg?f=webp"
          cdn="astro"
          layout="constrained"
          width={1023}
          height={682}
        />

Whereas setting the format using picture and source components works

        <picture>
          <UnpicAstroSource
            type="image/avif"
            src="/static/assets/images/owl.jpg"
            cdn="astro"
            width={1023}
            height={682}
          />
          <UnpicAstroSource
            type="image/webp"
            src="/static/assets/images/owl.jpg"
            cdn="astro"
            width={1023}
            height={682}
          />
          <UnpicAstroSource
            src="/static/assets/images/owl.jpg"
            cdn="astro"
            width={1023}
            height={682}
          />
          <UnpicAstroImage
            src="/static/assets/images/owl.jpg"
            cdn="astro"
            layout="constrained"
            width={1023}
            height={682}
          />
        </picture>

P.S.
I think my initial user error was not setting the cdn="astro"

EDIT: I can confirm that avif image transformations work in development, but fail in production (webp is fine)

@ascorbic
Copy link
Owner

ascorbic commented Jan 8, 2024

What you can do is pass in one of the generated endpoint URLs. That shoudl let you set the format, and it should also detect it as Astro

@jlarmstrongiv
Copy link
Contributor Author

Passing in one of the generated endpoint urls didn‘t work, since the passed url ended up in the href url parameter

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

No branches or pull requests

2 participants