qwikifiers / qwik-image Goto Github PK
View Code? Open in Web Editor NEWQwik Image Component
License: MIT License
Qwik Image Component
License: MIT License
Not much more to say than the title. Animated webp files also don't stay animated.
to reproduce:
import { component$ } from '@builder.io/qwik';
import ImgSpooky from '~/media/spooky.gif?jsx';
export default component$(() => {
return (
<div>
<ImgSpooky />
{/* spooky gif is lifeless like this isn't even halloween */}
</div>
)
});
ok I had a minute and I made a repo: https://git.sr.ht/~jeremyparker/qwik-animation-handling
It's seems reactivity is not working. The image component renders correctly on the first render, however, if you need to change any of the input props like it's layout or src after creating the component, it doesn't update.
This looks like it is because the logic for generating the src, sizes, and layouts is coded at the component level rather than in a reactive task$ or computed$ function.
Hello!
I think this calculation here is wrong:
https://github.com/qwikifiers/qwik-image/blob/main/packages/qwik-image/src/lib/image.tsx#L163
for await (const breakpoint of breakpoints.sort()) {
let transformedHeight =
typeof height === 'string' ? parseInt(height, 10) : height;
if (height && aspectRatio) {
transformedHeight = Math.round(breakpoint * aspectRatio);
^^^
}
The aspect ratio of an image is the ratio of its width to its height.
Aspect Ratio = Width / Height
Height = Width / Aspect Ratio
so if we want to transform the height we should divide the width by the aspect ratio
transformedHeight = Math.round(breakpoint / aspectRatio);
So we've just migrated from @unpic/qwik due to the transformers/detectors and API being MUCH better here in qwik-image where I can literally just pass a switch statement and tell it how to transform URLs.
One issue I've just noticed is that our frontend was using a lot of layout="fullWidth" and now I'm noticing a lot of image requests of 3840 width (double my screen width on a MBP M1 2021).
When I look at the documentation between the two libraries, this is how that property is described:
I can see that Gatsby behaviour is similar to qwik-image: https://www.gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-image/
Also, I see that unpic/react works the same as qwik-image (https://unpic.pics/img/learn/#layouts):
The fullWidth layout will stretch to the width of the screen, and is best for hero images and banners. Fixed images don’t scale at all, and are best for logos and icons.
I'm thinking that the way that it works for unpic/qwik is more useful than the functionality provided by qwik-image where it just uses 100% of the screen width as you're often trying to fill containers with images and want some help sizing them up depending on what's available.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.