View Full Version : Getting a certain image from a feed
X-Tream
02-03-2013, 12:38 PM
Hi,
First of all i'm using Simple Pie to get the images from my feed, but the problem is that the images are blurry. (http://netti-tv.net/yle) Is there a way to get a certain image from the feed (http://areena.yle.fi/tv/kaikki.rss)? In my case I would like to get the image ending "160.jpg".
Code what i'm using now is: http://pastebin.com/GCPXrkTQ and the part what is fetching the image is in line 88-89.
$enclosure = $item->get_enclosure();
$i['kuva'] = $enclosure->get_thumbnail();
Hopefully somebody can help! I would really appreciate it. :)
X-Tream
02-10-2013, 11:47 AM
Is there a solution for my problem for example using php array?
Beverleyh
02-10-2013, 12:19 PM
The script is pulling the thumbnail image that is associated with each news item - are you wanting it to pull a different image for each news item? Possibly a larger version?
And where does the "160.jpg" come in to play? Is that a common suffix for your larger version images? In other words, do you always use a series of thumbnail images with, for example, a "news-item-01.jpg" naming convention, and a larger version image series using a 160 suffix, as in "news-item-01-160.jpg"? I see that 160 is the img width declared in the original script echo (presumable when you say the image is blurry it is with reference to the script upsizing a much smaller source pic) but you haven't explained precisely why you mentioned it in your original post.
For reference to others, the script displays the the image thumbnail like this;
echo '<img border="0" title="'.$item['content'].'" width="160" src="'.$item['kuva'].'"/></a>';
Please explain your problem and requirements more clearly and then somebody might be able to offer suggestions.
X-Tream
02-10-2013, 03:26 PM
First of all thank you Beverleyh for answering my question.
Yes, I would like it to pull a larger image from the rss feed. Now it fetches the first image from the feed (Marked as Green and I would like to fetch the one ending in 160.jpq (Marked as red)): http://areena.yle.fi/tv/kaikki.rss
<item>
<title>
<![CDATA[ Yle Uutiset viittomakielellä: 10.02.2013 16.55 ]]>
</title>
<media:credit role="production department">Yle TV1</media:credit>
<areena:tvLicense>false</areena:tvLicense>
<link>http://areena.yle.fi/tv/1789751</link>
<guid isPermaLink="false">6b9365aef11e4db1a3121f6046093ad5</guid>
<description>
<![CDATA[ ]]>
</description>
<pubDate>Sun, 10 Feb 2013 16:55:00 +0200</pubDate>
<category>Uutiset</category>
<itunes:image href="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_720.jpg"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_65.jpg" width="65" height="37"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_160.jpg" width="160" height="90"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_220.jpg" width="220" height="124"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_620.jpg" width="620" height="349"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754.jpg" width="700" height="394"/>
<media:thumbnail url="http://areena.yle.fi/static/mk/images/previews/6b/6b9365aef11e4db1a3121f6046093ad5/6b9365aef11e4db1a3121f6046093ad5_1360508971754_720.jpg" width="720" height="405"/>
<dcterms:subject>
<![CDATA[ Yle Uutiset viittomakielellä ]]>
</dcterms:subject>
<dcterms:valid>
start=2013-02-10T16:55:00+0200; end=2013-03-12T23:59:59+0200; scheme=W3C-DTF;
</dcterms:valid>
<media:content duration="270"/>
</item>
And the "160.jpq" comes from the feed, as the feed has 6 thumbnails with different widths. So in my case 160 px width would be perfect for my site -> I should somehow grab the thumbnail ending in "160.jpg"
The reason why the image is blurry is course the line:
echo '<img border="0" title="'.$item['content'].'" width="160" src="'.$item['kuva'].'"/></a>';
Stretches the image bigger. From 65px -> 160px. To avoid this from happening I should somehow get the correct image size from the rss feed...And I believe you could somehow get it by using array?
Anyways sorry for my bad English, but yet again I would really appreciate if somebody could help me.
Beverleyh
02-10-2013, 04:51 PM
Ok - I'm on iPhone so I can't do any testing, but if your small (green) image always ends with "_65.jpg", and your bigger (red) image always ends with "_160.jpg", you can probably get away with doing something like this - add the extra line;
$enclosure = $item->get_enclosure();
$i['kuva'] = $enclosure->get_thumbnail();
$i['kuva'] = str_replace('65.jpg', '160.jpg', $i['kuva']);
X-Tream
02-10-2013, 05:48 PM
Thank you so much Beverleyh! It's finally fetching the correct image. :)
Beverleyh
02-10-2013, 06:27 PM
No problem :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.