[英]getting image size gives an error from rss feed
如果rss feed中的图像太小,我正在尝试创建自己的默认图像。
这是我的代码:
list($width, $height, $type, $attr) = getimagesize($item['item_img_path']);
if ($width > 75) {
$imgpath= $item['item_img'];
}else{
//no image found - default image
$imgpath = "<span class='fetched'></span>";
}
if ( $width > 75) {
$imgtest = 'image ( '.$width.' ) is larger than 75';
}else{
$imgtest = 'image ( '.$width.' ) is less than 75 <br>path is '. $item['item_img_path'].'<br> type is '.$type;
}
但是某些提要返回带有扩展媒体URL的媒体,如下所示:
<media:content width="460" url="https://i.guim.co.uk/img/media/330beb5c556c30ab7cba321f3b79241ab7b4d8af/782_922_7183_4310/master/7183.jpg?w=460&q=55&auto=format&usm=12&fit=max&s=a0cb25015876d9b0b7e4abec488f34b7">
现在,该图片显示在我的Feed中,但是当我尝试获取尺寸($ width)或键入它时,它将返回一个空白。
我以为可以通过更改以下行来绕开它:
if ($width > 75) {
至
if ( ($width > 75) || ($width ='')) {
但这并不会导致错误的陈述,因此只给出了我的跨度(默认图片)
因此,我还尝试将所有多余的尾随数据提取到媒体文件的“ jpg”之后,但仍无法给出图像的大小:
$s = strstr($item['item_img_path'], 'jpg', true).'jpg';
list($width, $height, $type, $attr) = getimagesize($s);
if ( ($width > 75) || ($width ='')) {
$imgpath= $item['item_img'];
}else{
//no image found - default image
$imgpath = "<span class='fetched'></span>";
}
if ( $width > 75) {
$imgtest = 'image ( '.$width.' ) is larger than 75';
}else{
$imgtest = 'image ( '.$width.' ) is less than 75 <br>path is '. $item['item_img_path'].'<br>s is '.$s.'<br> s type is '.$type;
}
导致我出现问题的RSS提要是:
https://www.theguardian.com/environment/energy/rss
媒体文件链接示例为:
这显示图像,但我无法获取尺寸。
并删除jpg之后的所有内容:
给出一个禁止的错误。 所以我不能给出尺寸。
您可以使用必须的信息从media.guim.co.uk中提取全幅图像。 将i.guim.co.uk/img/media/切换为media.guim.co.uk/,您会很方便:
https://media.guim.co.uk/330beb5c556c30ab7cba321f3b79241ab7b4d8af/782_922_7183_4310/master/7183.jpg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.