Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
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 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!