使用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&d=identicon&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&d=identicon&r=PG" alt="" width="324" height="324" class="avatar-me js-avatar-me">
当然,长宽比是另一个因素.
Then of course aspect ratio is the other factor.