Reputation: 83
I have this RSS feed working on my site but the images are way too big. Is there any way to make them smaller. The images come with the description element.
<?php
$rss = new DOMDocument();
$rss->load('http://www.keilir.net/is/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 2;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<small><em>Posted on '.$date.'</em></small></p>';
echo '<p>'.$description.'</p>';
}
?>
Upvotes: 0
Views: 1918
Reputation: 1699
If you'd like to change the image files themselves, you can use any number of PHP image libraries, which in the end tend to rely on the iMagick or GD PHP functions. To learn more about this, you could start here:
http://php.net/manual/en/class.imagick.php
http://php.net/manual/en/imagick.examples-1.php
Or try searching for PHP image libraries. If you would instead simply prefer to use the existing image files, but render them in a different size in the browser, you can simply specify height and width constraints using HTML attributes (or CSS):
<img src="/path/to/image" height="200" width="200" />
<img src="/path/to/image" style="height: 200px; width: 200px;" />
There are various caveats to this approach, namely that you will be asking the user to download a larger image than what they are seeing, meaning that the page will load slower than it needs to. Also, if you manually set the height/width of an image you will need to be careful to maintain the aspect ratio of the image, otherwise you will see it stretch or skew when rendered.
I strongly recommend you use PHP on the server-side to resize the images themselves, before using them on the page.
Upvotes: 2