Showing posts with label jpeg. Show all posts
Showing posts with label jpeg. Show all posts

Friday 18 May 2018

PNG to Jpeg in PHP using GD library


<?php
function png2jpg($originalFile, $outputFile, $quality) {
    $image = imagecreatefrompng($originalFile);
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
}
png2jpg("img/test.png", "img/".time().".jpg", 100);
if ($handle = opendir('img/')) {
	$i=0;
   while (false !== ($entry = readdir($handle))) {
      if ($entry != "." && $entry != "..") {
         echo "<img src='img/$entry' width=150 height=100>    ";
			if($i%10==0 && $i!=0){
				echo "<br>";
			}
			$i++;
      }
   }
   closedir($handle);
}
?>