• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

102
Views
img srcset and sizes not working in PHP/JavaScript

I am creating dynamic HTML from PHP. I wanted to resize images for mobile, but it doesn't seem to work. It picks up the larger image on my desktop with resolution 1440x900 as expected, but on my mobile the resolution shows up as 360x640 but it still picks up the larger image whereas I want it to pick the resized image. I am not an expert so any help would be appreciated.

<script language="javascript">
alert("Your screen resolution is: " + screen.width + "x" + screen.height);
</script>

        <?php
        print "<div class=\"row\">";
            print "<div class=\"img-P\">";
                print "<img srcset=\"images/resized/$img_resized 640w, images/$img 1024w\" 
                            sizes=\"(max-width: 640px) 640px, 1024px\" 
                            src=\"images/$img\"
                            loading=\"lazy\" />";
            print "</div>";
        print "</div>";
        ?>
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error