简体   繁体   中英

getting image size gives an error from rss feed

I'm trying to create a default image of my own if an image from rss feed is too small.

this is my code:

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;
}

but some of the feeds return media with an extended media url as in:

<media:content width="460" url="https://i.guim.co.uk/img/media/330beb5c556c30ab7cba321f3b79241ab7b4d8af/782_922_7183_4310/master/7183.jpg?w=460&amp;q=55&amp;auto=format&amp;usm=12&amp;fit=max&amp;s=a0cb25015876d9b0b7e4abec488f34b7">

now that image shows in my feed, but when i try to get a size ($width) or type it returns a blank.

I thought I could bypass that by changing this line:

if ($width > 75) {

to

if ( ($width > 75) || ($width ='')) {

but it made no difference still resulting in a false statement and thus giving just my span (default image)

so i also tried to pull all the extra trailing data after the "jpg" of the media file, but it still won't give the size of the image:

$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;
}

the rss feed causing me problems is:

https://www.theguardian.com/environment/energy/rss

an example media file link is:

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

this shows an image but i can't get dimensions.

and removing everything after jpg:

https://i.guim.co.uk/img/media/330beb5c556c30ab7cba321f3b79241ab7b4d8af/782_922_7183_4310/master/7183.jpg

gives a forbidden error. so i can't give dimensions.

You can use the info you have to pull the full-rez image from media.guim.co.uk. Switch i.guim.co.uk/img/media/ for media.guim.co.uk/ and you'll be good to go:

https://media.guim.co.uk/330beb5c556c30ab7cba321f3b79241ab7b4d8af/782_922_7183_4310/master/7183.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM