Soldato
- Joined
- 18 Apr 2004
- Posts
- 2,613
- Location
- London
Ok so I have a bit of PHP code which I use to generate my signature only when there are new images on my flickr profile and its fast because it caches the image until its actually needed but I was wondering if their is a way to make it quicker at all?
Also the PHP forum tag still doesn't work.
<?php
// Set headers + turn off error reporting
header('Content-type: image/jpeg');
header("Location: image.jpg");
error_reporting(0);
// Set configure location for the build.txt file
$location = "/";
$buildfile = $location . "build.txt";
// This is the add image function
function addImage($source, $destination, $offset) {
// Create a temporary image
$temp = imagecreatefromjpeg($source);
// Calculate image offset and 5px gap
$woffset = ((75 + 5) * $offset);
// Resample image into place
imagecopyresampled($destination, $temp, $woffset, 0, 0, 0, 75, 75, 75, 75);
// Destroy temp image
imagedestroy($temp);
}
// Get rss file
$xmldata = file_get_contents('http://www.flickr.com/services/feeds/photos_public.gne?id=62834984@N00&format=rss_200');
// Because PHP doesnt support flickrs semicolons, simply find and replace them
$xmldata = str_replace('media:thumbnail', 'mediathumbnail', $xmldata);
// Parse xml
$xml = simplexml_load_string($xmldata);
// Open build.txt file
$file = fopen($buildfile, 'r+');
$old = fread($file, filesize($buildfile));
// Read rss build date
$new = $xml->channel->lastBuildDate;
// Compare or if force option set then force a regeneration
if (trim($new) != trim($old) OR $_REQUEST['force']) {
// Save rss build to build.txt
ftruncate($file, 0);
fwrite($file, $new);
// Create image
$image = imagecreatetruecolor(395, 75);
// Define colours, (ocuk is 28,87,128 RGB)
$colour = imagecolorallocate($image, 28, 87, 128);
$white = imagecolorallocate($image, 255, 255, 255);
// Fill image background
imagefill($image, 0, 0, $colour);
// Add images (its 4 because it goes 0, 1, 2, 3, 4 not 1, 2, 3, 4, 5 as you might expect)
for ($i=0; $i <= 4; $i++) {
addImage($xml->channel->item[$i]->mediathumbnail['url'], $image, $i);
}
// Save image out
imagejpeg($image, 'image.jpg', 90);
// Destroy image
imagedestroy($image);
}
?>
Also the PHP forum tag still doesn't work.