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.

Read Also:  Yii Framework Introduction and Hello World Tutorial

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.

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:  Bootstrap On-Off Toggle Switch jQuery Plugins

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  What is the difference between a left join and a left outer join?
  2. Read Also:  how to resize image in php
  3. Read Also:  PHP Image Resize Tutorials
  4. Read Also:  Create Dynamic Web Pages using PHP-MYSQL
  5. Read Also:  PHP Ajax Image Upload Resize Crop using jQuery
  6. Read Also:  Image Resize Crop Thumbnail Watermark PHP Script
  7. Read Also:  Laravel 6 MySQL Get Last Inserted ID
  8. Read Also:  jquery Compress or resize Image File Size before Uploading PHP Code
  9. Read Also:  Global Config variable In Laravel 6 Example
  10. Read Also:  PHP Resize Image Upload Example