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
Parcel 2: HTML Image Transformer #3738
Comments
|
I wouldn't want this to be specific to HTML. I have a lot of my source images as SVG but sometimes need/want them rendered into other formats. For example:
All of these would have a use for images rendered into select formats at different resolutions. Can we try to find a solution that works uniformly wherever images are needed? |
It would be great to have this With my limited knowledge of Parcel, I see a Transformer reading HTML's AST from posthtml, transforming Is this done with the We should warn users that the HTML structure will be modified so their CSS must be resilient to that. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Related to the discussion around #6783 (comment), the addition of It would be safer to have it so <img src="./image.jpg" width="200"> wouldn't create a To have new <picture>
<img src="./image.jpg" width="200">
</picture> |
Reading https://www.smashingmagazine.com/2021/09/modern-image-formats-avif-webp/ and https://www.contentful.com/blog/2021/11/29/load-avif-webp-using-html/, I wonder if it should be like:
There's never going to be a silver bullet for this though. |
Create the
@parcel/transformer-html-images
(name TBD) package. This should include a Transformer plugin that transforms<img>
tags in HTML to<picture>
elements with multiple sources. It should work with the @parcel/transformer-webp and @parcel/transformer-image-resize plugins to create multiple dependencies that are transformed by those plugins and re-inserted later as URLs. This handles generating multiple versions of an image with different sizes and formats from a source HTML file and image completely automatically.HTML like this:
should be transformed into HTML like this, with dependencies created for each referenced asset:
This automatically handles creating both WebP and JPG versions of the image, at multiple resolutions.
In addition, the
srcset
attribute should be supported to generate multiple versions with specific sizes from the same input image:becomes:
Note that the protocol and query param syntax here is internal to Parcel and would not be shipped to users. After the images are transformed, the final URL would be placed into the HTML file as expected.
Open Questions
srcset
in their code themselves? Seems like it should be fairly common to want this...width
orheight
set on an<img>
? Just convert to WebP without resizing?The text was updated successfully, but these errors were encountered: