dtuzjzs3853 2011-09-28 12:36
浏览 38

PHP生成的特定图像尺寸

As we know, if we specify width and height attributes in <img /> element, browser can immidiately locate image in rendered layout. It's not a really big boost of speed, but it's really nice optimisation practice.

Ok, but sometimes image has different dimensions. So we can get it by PHP getimagesize() function.

And here is the question, if we don't have specific dimensions is it worthwhile to use PHP? Of course, we have to write additional code, but if we cope with gallery we anyhow use PHP, so in that case it's only 2 lines of code.

What is your opinion?

  • 写回答

4条回答 默认 最新

  • dongta1824 2011-09-28 12:44
    关注

    It depends on what you're trying to do. The benefits of having the dimensions on the <img/> tag are:

    1. Browser knows the space to reserve for the image as it's downloaded. This means your layout won't jump around as the images load.
    2. It saves the browser from performing a reflow and repaint once the images load (speed optimization).
    3. You'll have the dimensions available to any Javascript processing as soon as the HTML is finished loading.

    On the other hand, adding the dimensions will increase your page size and cause you to use more bandwidth.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)