Reputation: 23
I'm trying to work out the best way to degrade the quality of a jpeg image in a web page like this http://vimeo.com/3750507
Is there a server-side way of saving and re-saving at a lower quality then displaying an image each time the page is served?
Thanks in advance.
Upvotes: 1
Views: 114
Reputation: 13014
The following script will degrade the original image by 1 'quality point' on each page load, starting at 99. This isn't very robust, but should clearly demonstrate the concept.
Warning: this will replace the original image! Use a copy if the original is important!
session_start();
if (empty($_SESSION['quality'])) $_SESSION['quality'] = 99;
$file = 'degrade.jpg';
imagejpeg(imagecreatefromjpeg($file), $file, $_SESSION['quality']);
$_SESSION['quality']--;
header('Content-type: image/jpeg');
echo file_get_contents($file);
On first page load:
Tenth page load:
One hundredth page load:
Upvotes: 3