Hey there ive got this code, and it works nice but theres one thing: it saves a resized image... i dont want that, i want them resized on the fly and the original image kept intact at all cost!
heres the code:
function gallery($randomphoto3[picture]) {
$randomphoto="SELECT * FROM photos ORDER BY RAND() LIMIT 1";
$randomphoto2=mysql_query($randomphoto) or die("Could not get a random photo");
$randomphoto3=mysql_fetch_array($randomphoto2);
// The file
$filename = $_SERVER['DOCUMENT_ROOT']."/images/gallery/$randomphoto3[picture]";
// Set a maximum height and width
//$width = 125;
//$height = 125;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, $filename, 100);
return $randomphoto3[picture];
}
How should i modify this code to work the way i want? i thought on editing this part:
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
but i have no clue how 🙁