I am working on an image upload and using PHP in order to save the file on server. I want to resize the image to 256px x 256px and I am using the following code but the final image is not 256px x 256px May someone offer any suggestions?
$promo_image = $_FILES['promo_image']['name'];
if($promo_image != "") {
$ext = pathinfo($promo_image, PATHINFO_EXTENSION);
$promolink = "uploads/Image/".uniqId().uniqId().uniqId().".".$ext;
list($width, $height) = getimagesize($_FILES['promo_image']['tmp_name']);
if(strtolower($ext) == "png")
$original = imagecreatefrompng($_FILES['promo_image']['tmp_name']);
else
$original = imagecreatefromjpeg($_FILES['promo_image']['tmp_name']);
$resized = imagecreatetruecolor(256,256);
imagecopyresampled($resized, $original, 0, 0, 0, 0,256 ,256, $width, $height);
if(strtolower($ext) == "png")
imagepng($resized, $promolink);
else
imagejpeg($resized, $promolink);
move_uploaded_file($_FILES['promo_image']['tmp_name'], $promolink);
}
Below sharing the code that I use and tested too many times.