IgotaBreizh | Bonjour,
Je commence à m'autoformer sur les biblio GD. J'ai récupéré ce bout de code, qui permet de faire un image à partir d'un flux rss :
Code :
- <?php
- $url = "http://www.kerweb.fr/wp-rss.php"; //Should be a full URL, not a local reference.
- $displayname = "Kerweb.fr";
- $middle = "dernierement :";
- $rssHeadline = 0; //Which headline to display. 0 is the latest, 1 is the 1st one before the latest, 2 is the 2nd before latest, etc
- $filename = "sig.jpg"; //File name to save the image as
- $minutes = 5; //How often to update the image. 0 indicates that image updates every time it is called (heavy strain on bandwidth & server)
- $forcewidth = 0; //If set to 0, image will be as long as it needs to be. If set to anything else, image will be set at a forced width. Any text that doesn't fit will be cut off
- //In-URL definitions. Allows you to customize the image while calling it. If you're worried that others may
- //be exploiting your server to run their own image, remove the following chunk or comment it. Also note, when
- //using an in-URL definition, image file will not be created and the RSS file will be querried each time. This
- //should only be used wisely.
- if ($_GET['url']) { $url = $_GET['url']; $minutes = 0; $save = FALSE;}
- if ($_GET['displayname']) { $displayname = $_GET['displayname']; $minutes = 0; $save = FALSE;}
- if ($_GET['middle']) { $middle = $_GET['middle']; $minutes = 0; $save = FALSE;}
- if ($_GET['rssHeadline']) { $rssHeadline = $_GET['rssHeadline']; $minutes = 0; $save = FALSE;}
- if ($_GET['forcewidth']) { $forcewidth = $_GET['forcewidth']; $minutes = 0; $save = FALSE;}
- //If file's modify time is too recent, just load the image instead of creating it again
- if ($minutes > 0 && is_file($filename) && ((time()-filemtime($filename)) < ($minutes * 60))) {
- header("Content-type: image/jpeg" );
- $im = imagecreatefromjpeg($filename);
- imagejpeg($im,"",100);
- die;
- }
-
- $rdfHandle = fopen($url,"r" ) ; // Open the RDF file for reading
- $rdfData = fread($rdfHandle,10000) ; // Read in the RDF data.
- $rdfData = chop($rdfData); // Strip any whitespace from the end of the string
- $rdfData = ereg_replace("[\r,\n]", "", $rdfData); //Clear line breaks
- $rdfData = strstr($rdfData,"<item" ); //Remove everything before <item>.
- $rdfData = str_replace("<item>","", $rdfData); //Remove <item> itself
- $rdfData = urldecode($rdfData); //Replace any silly %20-type characters with their readable replacement.
- $rdfArray = explode("</item>",$rdfData); //Creates an Array from all the headlines
- $title = ereg_replace("<title>","",$rdfArray[$rssHeadline]); // Remove the leading <title> tags from the selected headline
- $title = str_replace(strstr($title,"</title>" ),"",$title); // Remove </title> and anything after it
- $title = trim($title);
- // create the image with appropriate dimensions
- $width = ((strlen($title) + strlen($middle) + strlen($displayname)) * ImageFontWidth(2)) + 10;
- if ($forcewidth > 0) { $width = $forcewidth;}
- $im = imagecreate($width, 15);
- $bg = imagecolorallocate($im, 255, 255, 255); //Color of background; currently white
- $textcolor = imagecolorallocate($im, 0, 0, 0); //Color of text; currently black
- $middlecolor = imagecolorallocate($im, 128, 128, 128);//Color of $middle text; currently gray
- // Write the string onto the image then save it
- imagestring($im, 2, $width - (strlen($title) * 6) - (strlen($middle) * 6) - 4, 1, $middle, $middlecolor);
- imagestring($im, 2, $width - (strlen($title) * 6), 1, $title, $textcolor);
- imagestring($im, 2, 2, 1, $displayname, $textcolor);
- if ($save != FALSE) { imagejpeg($im,$filename,100); }//Save file
- // output the image
- header("Content-type: image/jpeg" );
- imagejpeg($im,"",100);
- ?>
|
Et voilà ce que ça donne :
Est-ce que vous voyez pourquoi je n'arrive pas à récupérer ce flux rss (qui fonctionne pourtant bien chez moi) ?
Merci d'avance à ceux qui pourront m'aiguiller. |