[英]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.