PHP Image Resize Tutorials

Today, We want to share with you PHP Image Resize Tutorials.In this post we will show you How to upload and resize image in PHP, hear for Copy and resize part of an image using PHP we will give you demo and example for implement.In this post, we will learn about php image resize without losing quality with an example.

PHP Image Resize Tutorials

There are the Following The simple About PHP Image Resize Tutorials Full Information With Example and source code.

As I will cover this Post with live Working example to develop php image resize and save to folder, so the image upload with thumbnail in php for this example is following below.

Also Read :  Vue js Axios File Upload using PHP

Get Orignal Image Resource Id for Source Image

$file = "pakainfo.jpg"; 
$img_src_info = getimagesize($file);
$getImgType = $img_src_info[2]; 
if( $getImgType == IMAGETYPE_JPEG ) {   
$final_id_img_resource = imagecreatefromjpeg($file);  
}
elseif( $getImgType == IMAGETYPE_GIF )  {  
$final_id_img_resource = imagecreatefromgif($file);  }
elseif( $getImgType == IMAGETYPE_PNG ) {
$final_id_img_resource = imagecreatefrompng($file); }

Example: PHP Image Resize

index.php

<?php
if(isset($_POST["submit"])) {
	if(is_array($_FILES)) {
		$file = $_FILES['img_uploaded']['tmp_name']; 
		$img_src_info = getimagesize($file);
		$getImgType = $img_src_info[2]; 
		if( $getImgType == IMAGETYPE_JPEG ) {   
		$final_id_img_resource = imagecreatefromjpeg($file);  
		$final_img_results = fn_resize($final_id_img_resource,$img_src_info[0],$img_src_info[1]);
		imagejpeg($final_img_results,$_FILES['img_uploaded']['name'] . "_thump.jpg");
		}
		elseif( $getImgType == IMAGETYPE_GIF )  {  
			$final_id_img_resource = imagecreatefromgif($file);
			$final_img_results = fn_resize($final_id_img_resource,$img_src_info[0],$img_src_info[1]);
			imagegif($final_img_results,$_FILES['img_uploaded']['name'] . "_thump.gif");
		}
		elseif( $getImgType == IMAGETYPE_PNG ) {
			$final_id_img_resource = imagecreatefrompng($file); 
			$final_img_results = fn_resize($final_id_img_resource,$img_src_info[0],$img_src_info[1]);
			imagepng($final_img_results,$_FILES['img_uploaded']['name'] . "_thump.png");
		}
	}
}
function fn_resize($final_id_img_resource,$width,$height) {
	$thumb_w =200;
	$thumb_h =200;
	$final_img_results=imagecreatetruecolor($thumb_w,$thumb_h);
	imagecopyresampled($final_img_results,$final_id_img_resource,0,0,0,0,$thumb_w,$thumb_h, $width,$height);
	return $final_img_results;
}
?>
<form name="wpimgsourcefrm" action="" method="post" enctype="multipart/form-data">
<input type="file" name="img_uploaded" /> 
<input type="submit" name="submit" value="Submit" />
</form>

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Also Read :  JavaScript Preview Image before Upload with jQuery

I hope you get an idea about PHP Image Resize Tutorials.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.