I am creating a dynamic wallpaper/icon/etc site for a friend of mine. She obviously wants to offer several resolutions of her wallpapers. To save server space, I am only uploading the largest resolution, then using the GD library functions to create lower resolution files.
Currently I have a PHP file called "shrink.php", which receives an ID # for the wallpaper, a desired width, and a desired height. It works great, but when you right click the image and select "Save as...", you get a filename "shrink.php.jpg".
This isn't the end of the world, but I'd like to somehow change this so that it looks nicer for the enduser.
Here is my code, with sensitive information hidden:
<?php
// Generate header
header('Content-type: image/jpeg');
// Get data
$id = $_REQUEST['id'];
$width = $_REQUEST['w'];
$height = $_REQUEST['h'];
// Get source filename
$dbh = mysql_connect("******", "*******", "*******") or die (mysqlerror());
mysql_select_db("*********");
$query = "select standfile from wallpapers where id='" . $id . "'";
$sth = mysql_query($query,$dbh);
$row = mysql_fetch_array($sth);
$srcfile = "/var/www/domains/glossies.net/docs" . $row['standfile'];
// Create images in memory
$source = imagecreatefromjpeg( $srcfile );
$thumb = imagecreatetruecolor( $width, $height );
// Resize
imagecopyresampled( $thumb, $source, 0, 0, 0, 0, $width, $height, imagesx($source), imagesy($source) );
// Output
imagejpeg( $thumb, null, 100 );
imagedestroy($thumb);
?>
The "standfile" variable is a path to the standard-format wallpaper on the server. We also will be hosting wide-format, which is why I explicitly named it that.
Also, as I said, this process is a bit slow. Does anyone have any ideas to speed up the process without resorting to using more server space?