PHP Image Resize

PHP Image Resize

When we working with php,sometimes we need to use php image resize and upload.In this article we learn how to php image upload and resize.If you use my code your image will uploaded and also resized automatically depending your defined image size.At first we see how to use a form to upload an image.

Upload Form in HTML

Using this form you need to upload image from html.Then go to your action.php file.For php image resize and upload.Let see how to upload and resize image.

PHP Image Resize and Uploaded

Here i describe how to work this php image resize and upload.At first i took the file name in a variable.Then also get the file extension from this file.

Get Image Extension From Image Name

$path = $_POST['image']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);

Using file extension i convert the image with a new size.Then i get image size(height,width) from existing image,and also set a new image size.

Then create a thumb image using new image size.By using imagecreatetruecolor().Like

Create Thumb Image

imagecreatetruecolor( 100, 100 );

Then i check the image extension if that image is png i create a new image from png using this function imagecreatefrompng().Then i use imagecopyresized() and imagepng() function for create a new image depending on existing and new image size.

If the image extension is jpg i use some other function which is already defined in my code.In imagepng() or imagejpeg() function you need to set your upload directory.In this directory the resized image will uploaded.

So this is the technique for php image resize and upload.Enjoy and use !!!!!!!