dpjpo746884 2014-11-03 03:05
浏览 14

在PHP或Java中模仿srcset HTML 5属性

I have an array with URLs for download:

$urls = array(
    'http://ads.320x60.us.dizplayzone.com/1.png',
    'http://ads.480x90.us.dizplayzone.com/1.png',
    'http://ads.768x120.us.dizplayzone.com/1.png',
    'http://ads.900x150.us.dizplayzone.com/1.png',
    'http://ads.320x60.us.dizplayzone.com/2.png',
    'http://ads.480x90.us.dizplayzone.com/2.png',
    'http://ads.768x120.us.dizplayzone.com/2.png',
    'http://ads.900x150.us.dizplayzone.com/2.png',
    'http://ads.320x60.us.dizplayzone.com/100.png',
    'http://ads.480x90.us.dizplayzone.com/100.png',
    'http://ads.768x120.us.dizplayzone.com/100.png',
    'http://ads.900x150.us.dizplayzone.com/100.png',
    'http://ads.320x60.us.dizplayzone.com/200.png',
    'http://ads.480x90.us.dizplayzone.com/200.png',
    'http://ads.768x120.us.dizplayzone.com/200.png',
    'http://ads.900x150.us.dizplayzone.com/200.png',
    'http://ads.320x60.us.dizplayzone.com/300.png',
    'http://ads.480x90.us.dizplayzone.com/300.png',
    'http://ads.768x120.us.dizplayzone.com/300.png',
    'http://ads.900x150.us.dizplayzone.com/300.png',
    'http://ads.320x60.us.dizplayzone.com/55.png',
    'http://ads.480x90.us.dizplayzone.com/55.png',
    'http://ads.768x120.us.dizplayzone.com/55.png',
    'http://ads.900x150.us.dizplayzone.com/55.png',
    'http://ads.320x60.us.dizplayzone.com/12.png',
    'http://ads.480x90.us.dizplayzone.com/12.png',
    'http://ads.768x120.us.dizplayzone.com/12.png',
    'http://ads.900x150.us.dizplayzone.com/12.png');

The width of each of the images is found before the x.

Now the task is to find those URLs that match a given arbitrary screen resolution the best. So, for instance if the screen resolution is 1920x1080, the array would be shortened to only contain URLs that are 900 pixels wide (ie. http://ads.900x150.us.dizplayzone.com/12.png, http://ads.900x150.us.dizplayzone.com/55.png etc.)

If the screen resolution is 320x480 then the array would only contain http://ads.320x60.us.dizplayzone.com/12.png, http://ads.320x60.us.dizplayzone.com/55.png etc.)

What I want to mimic is basically the same behaviour as the srcset attribute for image tags in HTML5 using either PHP or Java.

After the array has been shortened the URLs still in the array can then be downloaded.

Can this be done?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单