PHP Resize Image Upload Example

Today, We want to share with you PHP Resize Image Upload Example.In this post we will show you php upload image generate thumbnail example, hear for How to upload and resize image in PHP ? we will give you demo and example for implement.In this post, we will learn about PHP image upload and resize it before uploading tutorial with an example.

PHP Resize Image Upload Example

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

As I will cover this Post with live Working example to develop Upload and Resize an Image with PHP, so the Image Upload and Resize it using PHP for this example is following below.

Also Read :  jquery Compress or resize Image File Size before Uploading PHP Code

index.php

<!DOCTYPE html>
<html>
<head>
	<title>PHP Image resize to upload - www.pakainfo.com</title>
</head>
<body>
<div class="container dsp">
	<form action="do_submit.php" method="post" enctype="multipart/form-data">
		<input type="file" name="image" /> 
		<input type="submit" name="submit" value="Submit" />
	</form>
</div>
</body>
</html>

do_submit.php

<?php
if(isset($_POST["submit"])) {
    if(is_array($_FILES)) {
        $file = $_FILES['image']['tmp_name']; 
        $img_src_data = getimagesize($file);
        $fl_new_name = time();
        $uploded_path = "upload/";
        $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
        $imageType = $img_src_data[2];
        switch ($imageType) {
            case IMAGETYPE_PNG:
                $img_main_id = imagecreatefrompng($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagepng($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
                break;
            case IMAGETYPE_GIF:
                $img_main_id = imagecreatefromgif($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagegif($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
                break;
            case IMAGETYPE_JPEG:
                $img_main_id = imagecreatefromjpeg($file); 
                $t_layer_data = imageResize($img_main_id,$img_src_data[0],$img_src_data[1]);
                imagejpeg($t_layer_data,$uploded_path. $fl_new_name. "_thump.". $ext);
                break;
            default:
                echo "YOUR Invalid Image type.";
                exit;
                break;
        }
        move_uploaded_file($file, $uploded_path. $fl_new_name. ".". $ext);
        echo "Image Resize Successfully.";
    }
}
function imageResize($img_main_id,$width,$height) {
    $targetWidth =200;
    $targetHeight =200;
    $t_layer_data=imagecreatetruecolor($targetWidth,$targetHeight);
    imagecopyresampled($t_layer_data,$img_main_id,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
    return $t_layer_data;
}
?>

Web Programming Tutorials Example with Demo

Read :

Also Read :  PHP Image Resize Tutorials

Summary

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

I hope you get an idea about simple Resize Image Upload using PHP.
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.

Leave a Reply

avatar
  Subscribe  
Notify of