如果图像太大,如何缩小尺寸?
在上面的链接中,您可以看到中间的新闻帖子有一个图像那太大了。 新闻信息是从数据库中取出的,因此我不确定如何仅更改某些图像上的图像宽度。理想情况下,我希望任何宽度超过 300 像素的图像都保持在 300 像素。这就是我到目前为止所拥有的:
echo '<img src="media/'.$row['media1'].'" class="floatLeftClear" id="border">';
我厌倦了在上面的语句中添加 width="300" ,但这使得所有图像都变成了我不想要的 300px 。我只想将大于 300 像素的图像缩小到 300。
有人能给我指出正确的方向吗?
On the above link you can see that the middle news post has an image that is just too big.
The info for the news is taken out of a database so I'm not sure how to change the width of the image on only certain images. Ideally I'd like to have any image that is over 300px wide to be kept at 300px. This is what I have so far:
echo '<img src="media/'.$row['media1'].'" class="floatLeftClear" id="border">';
I tired adding width="300" to the above statement but that made ALL of the images become 300px which I don't want. I only want images bigger than 300px to be reduced to 300.
Can someone point me in the right direction please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想在服务器上物理调整图像大小(这是理想的解决方案),您可以通过 CSS 设置
max-width
属性。请注意,IE6 及以下版本不支持该属性。
If you don't want to physically resize the images on the server, which would be the ideal solution, you can set the
max-width
property via CSS.Note that the property is not supported in IE6 and below.
该代码有助于调整图像大小。它的高度和宽度的调整取决于最大宽度,
但有一件事是图像大小(KB)没有减少。我希望它对你有帮助。
The code helps to resizing the image. its resize the height and width depends upon the max width
But one thing the image size(KB) is not reduce. I hope its help to you .
为什么不为新闻图像布局添加一个特殊的例程,在其中定义最大尺寸并为相关图像调用它?
Why not to add a special routine for news images layout, define max-size within it and call it for the related images?