使用PHP或CSS调整图像大小? [英] Resizing image with PHP or CSS?

查看:56
本文介绍了使用PHP或CSS调整图像大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个 div ,其中包含用户的照片.为了使照片完全充满div,我必须调整照片的大小.

Basically I have a div which contains a user's photo. In order for the photo to fill the div completely, I must resize the photo.

  • 问题是,我是编程的新手,我不确定哪种方法最适合调整图像的大小以适合div(我猜最可靠的方法是PHP).

我的问题是:我应该使用PHP函数来调整图像的大小,还是应该使用CSS设置指定的照片尺寸?(寻找最可靠的方法)

My question is: Should I resize the image using a PHP function, or should I be setting specified photo dimensions with CSS? (Looking for most robust method)

推荐答案

您可以看到StackOverflow如何做到的,只需在图像上设置宽度和高度即可.使用CSS进行描述时的想法...

You can see how StackOverflow does it, simply setting a width and height on the image. What you are thinking of when describing using CSS...

<img src="https://www.gravatar.com/avatar/6bc2ad4c62572ad8df0b54d91e17617f?s=48&amp;d=identicon&amp;r=PG" alt="" width="24" height="24" class="avatar-me js-avatar-me">

现在,该选项对于缩小尺寸非常有效,而对于图像放大尺寸则不太适用.让用户上传大小大于您将显示的最大大小的内容.否则,您将获得拉伸"的不良质量.

Now that works great for down-sizing, less so for image up-sizing. Get the user to upload something equal in size of larger than the maximum size you will display at. Otherwise you will get "stretched" poor quality.

<img src="https://www.gravatar.com/avatar/6bc2ad4c62572ad8df0b54d91e17617f?s=48&amp;d=identicon&amp;r=PG" alt="" width="324" height="324" class="avatar-me js-avatar-me">

当然,长宽比是另一个因素.

Then of course aspect ratio is the other factor.

这篇关于使用PHP或CSS调整图像大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆