PHP Auto image resizing Script

Today, We want to share with you PHP Auto image resizing Script.In this post we will show you Simple PHP image upload, resize and rename script?, hear for PHP Image Compression, Resize & Optimization we will give you demo and example for implement.In this post, we will learn about php image resize and save to folder with an example.

PHP Auto image resizing Script

There are the Following The simple About PHP Auto image resizing Script Full Information With Example and source code.

As I will cover this Post with live Working example to develop Copy and resize part of an image, so the resize image php before upload for this example is following below.

Read Also:  Number Filter using Angular Example

PHP Code Source

This PHP script Auto resize an Image into two 60px and 25px. Take a look at $newwidth you have to change your dynamic size values.

<?php 

 define ("MAX_SIZE","400");

 $get_errors=0;
 
 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
        $image =$_FILES["file"]["name"];
		 $getCatalogFile = $_FILES['file']['file_temp_name'];
		  if ($image) 
		  {
			  $filename = stripslashes($_FILES['file']['name']);
					$file_ext = fetchFileExtension($filename);
			  $file_ext = strtolower($file_ext);
			 if (($file_ext != "jpg") && ($file_ext != "jpeg") 

			&& ($file_ext != "png") && ($file_ext != "gif")) 
			  {
				echo 'Sorry, Unknown Image file_ext ';
				$get_errors=1;
			  }
			 else
			{
			   $size=filesize($_FILES['file']['file_temp_name']);
			 
			if ($size > MAX_SIZE*1024)
			{
				 echo "sorry, You have exceeded the size limit";
				 $get_errors=1;
			}
			 
			if($file_ext=="jpg" || $file_ext=="jpeg" )
			{
				$getCatalogFile = $_FILES['file']['file_temp_name'];
				$source = imagecreatefromjpeg($getCatalogFile);
			}
			else if($file_ext=="png")
			{
				$getCatalogFile = $_FILES['file']['file_temp_name'];
				$source = imagecreatefrompng($getCatalogFile);
			}
			else 
			{
				$source = imagecreatefromgif($getCatalogFile);
			}
			 
			list($width,$height)=getimagesize($getCatalogFile);

			$newwidth=60;
			$newheight=($height/$width)*$newwidth;
			$file_temp=imagecreatetruecolor($newwidth,$newheight);

			$img_width1=25;
			$img_height1=($height/$width)*$img_width1;
			$img_temp=imagecreatetruecolor($img_width1,$img_height1);

			imagecopyresampled($file_temp,$source,0,0,0,0,$newwidth,$newheight,

			 $width,$height);

			imagecopyresampled($img_temp,$source,0,0,0,0,$img_width1,$img_height1, 

			$width,$height);

			$filename = "images/". $_FILES['file']['name'];
			$filename1 = "images/small". $_FILES['file']['name'];

			imagejpeg($file_temp,$filename,100);
			imagejpeg($img_temp,$filename1,100);

			imagedestroy($source);
			imagedestroy($file_temp);
			imagedestroy($img_temp);
			}
		}
}


 if(isset($_POST['Submit']) && !$get_errors) 
 {
   // mysql_query("update SQL statement ");
  echo "Your Latest Image Uploaded Successfully!";

 }
 ?>

Global Methods get the Extention PHP funtion

Read Also:  PHP Image Resize Tutorials

simple PHP Finds file extensions.

function fetchFileExtension($str) {

         $i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about PHP Auto image resizing Script.
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.