This script is used to randomly select a background whenever you access the site. I do this by setting background-image in my stylesheet to this php file
It works fine, but the image is compressed heavily. Is there a way to keep the quality?
<?php
$img = array('dx1.jpg', 'dx2.jpg', 'dx3.jpg' ); // Adds the names of all images into an array
$i = rand(0, count($img)-1); // Generates a random number (max being the last element's index from the array)
$chosenimg = "$img[$i]"; // Sets the variable $chosenimg to equal to whatever the random image name was (from the above array)
$image = imagecreatefromjpeg($chosenimg);
imagealphablending($image, false);
imagesavealpha($image, true);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
?>
Aucun commentaire:
Enregistrer un commentaire