Resize Image in php,crop image in php

step1:Create file index.php

step2:create a form


if(isset($_REQUEST['add']))
{
$image =$_FILES["file"]["name"];
if(!empty($image))
{
//echo "hello";
error_reporting(0);
$change="";
$abc="";

define ("MAX_SIZE","400");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}

$errors=0;
$image =$_FILES["file"]["name"];
$uploadedfile = $_FILES['file']['tmp_name'];
if ($image)
{

$filename = stripslashes($_FILES['file']['name']);

$extension = getExtension($filename);
$extension = strtolower($extension);

if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{

$change='
Unknown Image extension
'; $errors=1; } else { $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024) { $change='
You have exceeded the size limit!
'; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=1400;/////////////////////////////////////////////////set image width $newheight=600;//////////////////////////////////////////////////set image height $tmp=imagecreatetruecolor($newwidth,$newheight); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); $filename = "images/silider/". $_FILES['file']['name']; $new_name=$_FILES['file']['name']; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); }}}else{ $image="Noimage.jpg"; } } ?> <form action="" enctype="multipart/form-data" method="post"> <input name="file" type="file" /> <input name="add" type="submit" /></form>  

Step:3 create folder name images-&gt;silider

step3:Now upload your image

Share Button

About admin

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Author: pramod kumar kumawat Mob: 9269727062
Free WordPress Themes - Download High-quality Templates