The following code resizes a png image and displays it as a jpg image:
<?php
header("content-type: image/jpg");
$file_name = 'img.png';
$srcsize = getimagesize($file_name);
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if($ext == ".jpg"){
$new_img_big = imagecreatefromjpeg($file_name);
}elseif($ext == ".png"){
$new_img_big = imagecreatefrompng($file_name);
}elseif($ext == ".gif"){
$new_img_big = imagecreatefromgif($file_name);
}
$resized_img_big = imagecreatetruecolor(100, 100);
imagecopyresized($resized_img_big, $new_img_big, 0, 0, 0, 0, 100, 100, $srcsize[0], $srcsize[1]);
imagejpeg($resized_img_big);
/*imagedestroy($src_img);
imagedestroy($dst_img);*/
?>
<?php
header("content-type: image/jpg");
$file_name = 'img.png';
$srcsize = getimagesize($file_name);
$ext = strrchr($file_name,'.');
$ext = strtolower($ext);
if($ext == ".jpg"){
$new_img_big = imagecreatefromjpeg($file_name);
}elseif($ext == ".png"){
$new_img_big = imagecreatefrompng($file_name);
}elseif($ext == ".gif"){
$new_img_big = imagecreatefromgif($file_name);
}
$resized_img_big = imagecreatetruecolor(100, 100);
imagecopyresized($resized_img_big, $new_img_big, 0, 0, 0, 0, 100, 100, $srcsize[0], $srcsize[1]);
imagejpeg($resized_img_big);
/*imagedestroy($src_img);
imagedestroy($dst_img);*/
?>
Comments
Post a Comment