Image – Resize Image – PNG to JPEG
if(substr($_FILES["photo"]["name"], -3) == 'png') {
png_2_jpg('pics/'.$_FILES["photo"]["name"], 80);
}
resize_image('path/image.jpg', 500);
function resize_image($img, $w){
list($width_orig, $height_orig) = getimagesize($img);
$dst_width = $w;
$dst_height = ($dst_width/$width_orig)*$height_orig;
$im = imagecreatetruecolor($dst_width,$dst_height);
$image = imagecreatefromjpeg($img);
imagecopyresampled($im, $image, 0, 0, 0, 0, $dst_width, $dst_height, $width_orig, $height_orig);
imagejpeg($im, $img);
imagedestroy($im);
}
function png_2_jpg($filePath, $q) {
$image = imagecreatefrompng($filePath);
$bg = imagecreatetruecolor(imagesx($image), imagesy($image));
imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
imagealphablending($bg, TRUE);
imagecopy($bg, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
imagejpeg($bg, $filePath, $q);
imagedestroy($bg);
}