Apakah Anda mencari script php untuk resize gambar , Saya telah mencoba menerapkan script PHP sederhana untuk membuat gambar ke dimensi yang berbeda. Ini sangat berguna untuk proyek web Anda untuk menghemat ruang hosting dan bandwidth untuk mengurangi gambar asli dengan ukuran terkompresi. Kode PHP Script ini mengubah ukuran sebuah gambar menjadi dua 60px dan 25px. Lihatlah $ newwidthAnda harus memodifikasi nilai-nilai ukuran.

<strong><?php</strong> 

 <a href="http://www.php.net/define">define</a> ("MAX_SIZE","400");

 $errors=0;

 if($_SERVER["REQUEST_METHOD"] == "POST")
 {
        $image =$_FILES["file"]["name"];
 $uploadedfile = $_FILES['file']['tmp_name'];

  if ($image) 
  {
  $filename = <a href="http://www.php.net/stripslashes">stripslashes</a>($_FILES['file']['name']);
        $extension = getExtension($filename);
  $extension = <a href="http://www.php.net/strtolower">strtolower</a>($extension);
 if (($extension != "jpg") && ($extension != "jpeg") 
&& ($extension != "png") && ($extension != "gif")) 
  {
<a href="http://www.php.net/echo">echo</a> ' Unknown Image extension ';
$errors=1;
  }
 else
{
   $size=<a href="http://www.php.net/filesize">filesize</a>($_FILES['file']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
 echo "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);
}

<a href="http://www.php.net/list">list</a>($width,$height)=<a href="http://www.php.net/getimagesize">getimagesize</a>($uploadedfile);

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

$newwidth1=25;
$newheight1=($height/$width)*$newwidth1;
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
 $width,$height);

imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1, 
$width,$height);

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

imagejpeg($tmp,$filename,100);
imagejpeg($tmp1,$filename1,100);

imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
}
}
}

 if(<a href="http://www.php.net/isset">isset</a>($_POST['Submit']) && !$errors) 
 {
   // mysql_query("update SQL statement ");
  <a href="http://www.php.net/echo">echo</a> "Image Uploaded Successfully!";

 }
 ?>

Ekstensi Fungsi PHP Menemukan ekstensi file.

function getExtension($str) {

         $i = <a href="http://www.php.net/strrpos">strrpos</a>($str,".");
         if (!$i) { return ""; }
         $l = <a href="http://www.php.net/strlen">strlen</a>($str) - $i;
         $ext = <a href="http://www.php.net/substr">substr</a>($str,$i+1,$l);
         return $ext;
 }

Oke sekian turorial sederhana yang pernah saya coba semoga bermanfaat untuk anda yang membacanya terimakasih.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s