Is it possible to have png images on my server but have a php script that converts them to jpg (and compresses them) and caches them when viewed?
Asked
Active
Viewed 158 times
2 Answers
3
You can use this script for convert PNG image into JPEG image.
$input_file = "test.png";
$output_file = "test.jpg";
$input = imagecreatefrompng($input_file);
list($width, $height) = getimagesize($input_file);
$output = imagecreatetruecolor($width, $height);
imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
imagejpeg($output, $output_file);
You can go through this @Alexandre Jasmin Answer.
-
It appears this doesn't cache the image, ie. they are regenerated each time the page is viewed (would this be a problem for speed?), what would I have to add to this script to cache? So it only generates a new jpg if the png has changed from the last time a jpg was generated. – Skyfish Apr 12 '15 at 06:18
1
yes it is possible, you can google it using phrase "png convert to jpg php"