PHP Image Resize Script Example

Today, We want to share with you Simple PHP Image Resize Source Code Demo with Example.In this post we will show you upload and resize image in php mysql, hear for php resize image before move_uploaded_file we will give you demo and example for implement.In this post, we will learn about resize image in php without losing quality with an example.

PHP Image Resize Script Example

There are the Following The simple About Simple Image File Resize Script Example Full Information With Example and source code.

Read Also:  jQuery Get Dynamic Element Selector Finding ID

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

How to resize image through php script

HTML Part

<form name="uploadimgFiles" action="" method="post" enctype="multipart/form-data">
<input type="file" name="uploadedImgFile" /> 
<input type="submit" name="submit" value="Submit" />
</form>

PHP Code

<?php
if(isset($_POST["submit"])) {
if(is_array($_FILES)) {
$file = $_FILES['uploadedImgFile']['tmp_name']; 
$file_data_content = getimagesize($file);
$image_type = $file_data_content[2]; 
if( $image_type == IMAGETYPE_JPEG ) {   
$file_rec_Id = imagecreatefromjpeg($file);  
$img_layer_path = file_resize_auto($file_rec_Id,$file_data_content[0],$file_data_content[1]);
imagejpeg($img_layer_path,$_FILES['uploadedImgFile']['name'] . "_thump.jpg");
}
elseif( $image_type == IMAGETYPE_GIF )  {  
$file_rec_Id = imagecreatefromgif($file);
$img_layer_path = file_resize_auto($file_rec_Id,$file_data_content[0],$file_data_content[1]);
imagegif($img_layer_path,$_FILES['uploadedImgFile']['name'] . "_thump.gif");
}
elseif( $image_type == IMAGETYPE_PNG ) {
$file_rec_Id = imagecreatefrompng($file); 
$img_layer_path = file_resize_auto($file_rec_Id,$file_data_content[0],$file_data_content[1]);
imagepng($img_layer_path,$_FILES['uploadedImgFile']['name'] . "_thump.png");
}
}
}
function file_resize_auto($file_rec_Id,$width,$height) {
$desct_w =200;
$desct_h =200;
$img_layer_path=imagecreatetruecolor($desct_w,$desct_h);
imagecopyresampled($img_layer_path,$file_rec_Id,0,0,0,0,$desct_w,$desct_h, $width,$height);
return $img_layer_path;
}
?>

Web Programming Tutorials Example with Demo

Read :

Read Also:  AngularJS Form Validation

Summary

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

I hope you get an idea about Image Resize Script in PHP Example.
I would like to have feedback on my infinityknow.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.