How to change thumbnail dimension based on URL

Question

I have a piece of code, I just want my thumbnail image size should be changed when I use this query…

Like

https://mywebsite.com/thumbnail.jpg?q=50&fit=crop&w=341&h=215&dpr=1.5

When I use the link my thumbnail should be in the above width and height.

<source media="(min-width: 1024px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 1024px) and (min-resolution: 120dpi)"
sizes="341px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=341&h=215&dpr=1.5"/>

<source media="(min-width: 1024px)"
sizes="341px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=341&h=215&dpr=1.5"/>

<source media="(min-width: 768px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 768px) and (min-resolution: 120dpi)"
sizes="377px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=377&h=300&dpr=1.5"/>

<source media="(min-width: 768px)"
sizes="377px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=377&h=300&dpr=1.5"/>

<source media="(min-width: 481px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 481px) and (min-resolution: 120dpi)"
sizes="294px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=294&h=234&dpr=1.5"/>

<source media="(min-width: 481px)"
sizes="294px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=294&h=234&dpr=1.5"/>

<source media="(min-width: 0px) and (-webkit-min-device-pixel-ratio: 1.25), (min-width: 0px) and (min-resolution: 120dpi)"
sizes="180px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=180&h=130&dpr=1.5"/>

<source media="(min-width: 0px)"
sizes="180px" srcset="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>?q=50&fit=crop&w=180&h=130&dpr=1.5"/>

How can I make this work?

0
Paul Simon 8 months 2020-12-05T16:10:41-05:00 0 Answers 9 views 0

Leave an answer

Browse
Browse