gpt4 book ai didi

php - 获取不在内容中的图像高度

转载 作者:行者123 更新时间:2023-11-30 18:32:17 24 4
gpt4 key购买 nike

我正在构建一个自定义的 wordpress 主题,并在首页上放映幻灯片,显示博客文章中的图片。

现在,如果图像的高度超过 300 像素,我想强制调整其宽度并将其垂直居中。所以我的问题是:

有没有办法在 php 或 javascript 中仅通过使用图像的 URL 来获取图像的高度?

编辑:我试过这个:<?php list($height) = getimagesize(echo catch_that_image()); echo "<p>$height</p>"; ?>其中 catch_that_image()返回 URL,但不知何故这不起作用(我认为第一个 echo 破坏了它)。有什么想法吗?

感谢您的帮助。

最佳答案

仅使用图像的 URL 图像?

var img = new Image();
img.onload = function() {
alert('The size is ' + this.width + 'x' + this.height);
};
img.src = 'some image URL';

试一试 http://jsfiddle.net/NPSMN/

附言:

I tried this: ... where catch_that_image() returns the URL, but somehow this doesn't work (I think the first echo breaks it). Any ideas?

您是否仔细查看了您的代码? echo 输出到浏览器,而不是函数的参数。

<?php 
list(,$height) = getimagesize(catch_that_image());
echo "<p>$height</p>";
?>

关于php - 获取不在内容中的图像高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9303787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com