Cloudinary responsive images
Hi, I have a website using netlify cms and I have cloudinary. When using images in a blog post they are not responsive. If I read correct the documentation, it should do the trick ( of part of it) when : w_auto,c_scale . Nothing happens. It goes way bigger.
What I am doing wrong?
Thank you
-
Hi Ricardo,
Passing only w_auto in the URL will not adjust the width but it needs to be done in combination with the javascript.
The best way is to let our JS library take care of the "conversion" fromw_autoto the right value.Therefore, the
w_autoURL should be inside thedata-srcattribute. Also, thecld-responsivemust be also defined for each image.
For example:<img data-src="https://res.cloudinary.com/demo/image/upload/w_auto,c_scale/smiling_man.jpg" class="cld-responsive">Note that in this example, there's no
srcvalue at all.
Then with a few lines of code, our JS library will be instructed to go over all of these images, will calculate the corresponding breakpoint, then assign thesrcattribute with the correct value (e.g.,w_1500instead ofw_auto).
For example:var my_breakpoints = [500,1000,1500]; var cl = cloudinary.Cloudinary.new({cloud_name: "<your cloud name>"}); cl.config({breakpoints:my_breakpoints, responsive_use_breakpoints:true}) cl.responsive();This will restrict the breakpoint assignment to only 500, 1000, and 1500. So for your question, yes, only three derivatives will be created.
You can see this in action in the following link:
https://jsfiddle.net/taragano/qa62k59L/For more information:
https://cloudinary.com/documentation/responsive_images#automating_responsive_images_with_javascriptIf you continue seeing the issue then please share the website link where this can be tested further.
Regards,Aditi
0
Post is closed for comments.
Comments
1 comment