Tak wygląda kod:
if ($action == "new_media") { if ($_FILES['image']['name'] != "") { $errors= ""; $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp_name']; $file_type = $_FILES['image']['type']; //$file_name = "defaultimage".$file_ext; $errors="extension not allowed, please choose a JPEG or PNG file.<br>"; } if($errors=="") { if($file_ext == "png"){ $images = $_FILES["image"]["tmp_name"]; $width=800; $height=450; $images_orig = imagecreatefrompng($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); $white = imagecolorallocate($images_fin, 255, 255, 255); imagefilledrectangle($images_fin, 0, 0, $width, $height, $white); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width, $height, $photoX, $photoY); ImageJPEG($images_fin,"../images/uploads/".$new_images); ImageDestroy($images_orig); ImageDestroy($images_fin); }else{ $images = $_FILES["image"]["tmp_name"]; $width=800; $height=450; $images_orig = ImageCreateFromJPEG($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width, $height, $photoX, $photoY); ImageJPEG($images_fin,"../images/uploads/".$new_images); ImageDestroy($images_orig); ImageDestroy($images_fin); } } }else{ echo '<div class="alert alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button><strong>Please Browse a new Image!</strong></div>'; }