Archive
Image Resize
<?php function filecheck($imagename) {
$extension = explode(“.”, $imagename);
$image =”0″;
if(preg_match(“/jpg|JPG|jpeg|JPEG/”, end($extension)))
{
$image =”1″;
}
elseif(preg_match(“/png|PNG/”, end($extension)))
{
$image =”1″;
}
elseif(preg_match(“/gif|GIF/”, end($extension)))
{
$image =”1″;
}
elseif(preg_match(“/bmp|BMP/”, end($extension)))
{
$image =”1″;
}
return $image;
}
//error_reporting(0);
function get_slug($data) {
return str_replace (‘ ‘,’_’,$data);
}
if(isset($_POST[‘submit’]))
{
if($_FILES[‘image1’][‘name’])
{
$fimage1=basename($_FILES[‘image1’][‘name’]);
$upload_dir=”uploads/images/”;
$sim1=filecheck($fimage1);
$random=rand(1,10000);
if($sim1==1) {
$upload_file=$upload_dir.get_slug($random.basename($_FILES[‘image1’][‘name’]));
move_uploaded_file($_FILES[‘image1’][‘tmp_name’],$upload_file);
$im1=basename($_FILES[‘image1’][‘name’]);
}
if(!empty($im1)) {
$image_name1=get_slug($random.basename($_FILES[‘image1’][‘name’]));
} else {
$image_name1=””;
}
$imagefolder=’uploads/images/’;
$thumbsfolder=’uploads/thumb/’;
$width=’100′;
$height=’100′;
$nwidth=’400′;
$nheight=’400′;
require_once(‘includes/imageResize.class.php’);
if(!empty($im1)) {
$fileSavePath=$imagefolder.$image_name1;
$newFileName=$thumbsfolder.”tn_”.$image_name1;
list($width1,$height1)=getimagesize($fileSavePath);
$y=$width1;
$x=$height1;
//$x=imagesx($fileSavePath);
// $y=imagesy($fileSavePath);
if($x>700 || $y>700) {
imagejpeg(imageResize::Resize($fileSavePath,$nwidth,$nheight),$fileSavePath);
}
imagejpeg(imageResize::Resize($fileSavePath,$width,$height),$newFileName);
}
}
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<body>
<form method=”POST” action=”” enctype=”multipart/form-data” >
<input name=”image1″ type=”file” id=”image1″ />
<input type=”submit” id=”submit” name=”submit” value=”Submit” />
</body>
</html>