如何动态查找图像宽度和高度,并在超过特定尺寸时指定高度、宽度属性?
我在网站上显示一些数据,其中一个数据源元素是图像。
[title] => Product title
[description] => some description
[image] => www.some-domain.com/product-image/p12345.jpg
然后,我使用
<img alt="product" src="<?=$data['image']?>" />
大多数图像的宽度为 80x80、120x100 或其他小于 150 的图像来显示此图像,这完全适合网站模板,但其中一些图像非常大,例如 800x600,这会扭曲布局。我想要对这些类型进行控制。
我尝试设置 WIDTH="150",但随着宽度的变化,它们看起来不太好。我在想如果我可以为图像设置一个固定宽度,比如说大于 250px,那么我现在就可以忍受它了。 有什么想法如何实现这一目标?
谢谢
I display some data on my website and one of the data feed elements is an image.
[title] => Product title
[description] => some description
[image] => www.some-domain.com/product-image/p12345.jpg
I then display this image using
<img alt="product" src="<?=$data['image']?>" />
Most of the images are 80x80, 120x100 or other less than 150 in width, which perfectly fit in the website template, but some of them are quite large such as 800x600 which distort the layout. I want a control on these types.
I tried to set WIDTH="150", but as the width vary they dont look good. I was thinking If I could set a fixed width to images, say, larger than 250px then I can live with it for now.
Any ideas how to achieve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用 getimagesize() 来实现这一点。
I have used getimagesize() for exactly this.