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:  Image Resize Crop Thumbnail Watermark PHP Script

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:  PHP Auto image resizing Script

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.

Summary
Review Date
Reviewed Item
692 - Users
Author Rating
51star1star1star1star1star

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  jquery Compress or resize Image File Size before Uploading PHP Code
  2. Read Also:  List WooCommerce Products by Tags - wordpress plugin
  3. Read Also:  PHP Image Resize Tutorials
  4. Read Also:  CodeIgniter Login Registration Example Tutorial From Scratch
  5. Read Also:  Upload Multiple Images Preview using PHP
  6. Read Also:  how to resize image in php
  7. Read Also:  how to check and know my jio Mobile number From MyJio App or using Jio4GVoice App?
  8. Read Also:  PHP Image Resize, Crop, Thumbnail, Watermark
  9. Read Also:  how to integrate stripe payment gateway in php?
  10. Read Also:  Insert Update Delete view function using PHP and mysql - crud function
CLOSEX