获取内容中未包含的图像高度
我正在构建一个自定义 WordPress 主题,并在首页上有一个幻灯片,显示博客文章中的图像。
现在,如果图像的高度超过 300 像素,我想强制其宽度并将其垂直居中。所以我的问题是:
有没有一种方法,在 php 或 javascript 中仅使用图像的 URL 来获取图像的高度?
编辑:我尝试了这个: $高度"; ?>
其中 catch_that_image()
返回 URL,但不知何故这不起作用(我认为第一个回声会破坏它)。有什么想法吗?
感谢您的帮助。
I am building a custom wordpress theme and have a slideshow on the front page displaying images from blog posts.
Now if the image is over 300px in height I want to force its widthand center it vertically. So my question is:
Is there a way, in php or javascript to get the height of an image by only using the URL of the image?
EDIT: I tried this: <?php list($height) = getimagesize(echo catch_that_image()); echo "<p>$height</p>"; ?>
where catch_that_image()
returns the URL, but somehow this doesn't work (I think the first echo breaks it). Any ideas?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅使用图像的 URL 来生成图像?
尝试一下
http://jsfiddle.net/NPSMN/
ps:
你仔细看看你的代码吗?
echo
输出到浏览器,而不是函数的参数。image by only using the URL of the image?
Try it
http://jsfiddle.net/NPSMN/
ps:
did you look closer at your code?
echo
outputs to the browser, not to the argument of the function.请参阅 PHP 中的 getimagesize()。这将满足您的需求。
http://php.net/manual/en/function.getimagesize.php
See getimagesize() in PHP. That will do what you're looking for.
http://php.net/manual/en/function.getimagesize.php