React image component width
Hey,
I'm experimenting with the react image, and I'm trying to create a header image. I want the image to be 100vh height and width for every screen, and i want to crop the image to it's center.
In my library i have an image at the size of 1920 × 1275.
My react component is:
I have tried few settings, such as:
-
Hey Yarden,
Notice that though the Client Hints solution seems to be the easiest and intuitive way to go, it is currently partly restricted by Google (due to privacy concerns), and works only on the mobile version of Chrome. More information regarding Client Hints and Cloudinary can be found here.
Therefore it is currently recommended to use our JavaScript solution for responsive images.
Do you aim at delivering the images on mobile Chrome only? Have you tested this code on mobile Chrome?
Thanks,
Eyal
0 -
Hey,
Thanks for the answer, but I can't seem to figure out how to use the sdk with react.
Do you happen have any small example projects maybe?I've installed the package and imported it into the component.
In the component I've set:let cl=newcloudinary.Cloudinary({cloud_name:"my-cloud-name", secure:true});cl.responsive();and then:
<sectionclassName="header-container"><imgclassName="cld-responsive"/></section>When checking the console, I see there is no src attribute. What is the right way to integrate it with react?
Thanks0 -
Following is a simple example of achieving responsive images behavior (after installing the React SDK - following the integration steps provided here) -
First import the relevant components -import {Image, Transformation} from 'cloudinary-react';Then rendering the image -render() {return (<div><Image cloudName="<cloud_name>" dpr="auto" responsive width="auto" crop="scale" publicId="sample"><Transformation effect="cartoonify"/></Image></div>);}Hope this helps! let me know if you have any further questions.0 -
Hey,
Thanks for the example.
The problem was the dpr. When I set it to auto, for some reason my laptop was detected to 2, that is why the url was fetching such a huge image. I removed the dpr attribute and now it works very well.Thanks a lot for the help!
0 -
Sure! Glad it worked out.
0
Post is closed for comments.
Comments
5 comments