How To Reduce or Compress Image Size In Php-Full Detail

How To reduce Image Size In Php

Compress Image In Php-

Hello Friends Ajj Me Apko Btaunga Ki Kis Parkar Ham Imagesize Reduce Kar Sakte Hai Php Ki Help Se.
Ajj Mere Is Post Me Mai Apko  Me Image Compression Tool Bnana Sikhaunga Jiski Madad Se Aap Image Compress Kar Sakte Ho Or Sath He Apne Liye Ek Image Compression Website Aur Tool Teyar Kar Sakte Ho

Aap Is Script Ka Use Karke Upper Dig Ye Website Ki Trah Apne Website Teyar Kar Sakte Ho
Steps-
Yanha Apko Do File Create Karne Hai-
·         Make a index.php-sabse pehle ham ek index.php name se file create karege jis file me ham form bnayege janha image upload karne ka option hoga,is form ka use karke user apni image upload karega.
·         Make a  form.php- ab ham php imagecomression function ka use karke ek script bnayege .yanha ham mainly 3 function ka use karege.
·         Imagecreatefromjpeg
·         Getimagesize-yeh function hame image ke size,width hight ko check karega
·         File_get_contents-ye function file ke content ko sting me read karega.



Sabse pehle aap index.php file me Niche Diya Gya Code Copy Kar Lijiye
Index.php





<center>

Upload Image

<form action="form.php" name="myform" id="myform" method="post" enctype="multipart/form-data">



        

<label>Upload:</label>

                                <input type="file" name="file" id="file"/><br>

<input type="hidden" value="sonu" name="file1"/><br/>

<br>

choose your extension<select name="ext">

<option value=".jpg">.jpg</option>

</select><br/>



<input type="submit" name="submit" id="submit" class="submit btn-success"/>



</form>

</center>





Ab aap ek form.php Name Ki File Bnaiye Or Wanha  Niche Diya Gya Code Paste Kar Dijiye
form.php



<?php



if(isset($_POST['submit'])){



function compress_imagesize($source_url, $dest_url, $quality) {



$info = getimagesize($source_url);



     if ($info['mime'] == 'image/jpeg')

         $image = imagecreatefromjpeg($source_url);



imagejpeg($image, $dest_url, $quality);

return $dest_url;

}



if (

           ($_FILES["file"]["type"] == "image/jpeg"))



{





        $f=$_POST['file1'];



               $ext=$_POST['ext'];

                   $imagename = $f.$ext;



         $filename = compress_imagesize($_FILES["file"]["tmp_name"], $imagename , 50);

         $imageshow = file_get_contents($imagename );



         /* Force download dialog... */

         header("Content-Type: application/force-download");

         header("Content-Type: application/octet-stream");

         header("Content-Type: application/download");



/* Don't allow caching... */

         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");



         /* Set data type, size and filename */

         header("Content-Type: application/octet-stream");

         header("Content-Transfer-Encoding: binary");

         header("Content-Length: " . strlen($imageshow));

         header("Content-Disposition: attachment; filename=$imagename ");



         /* Send our file... */

         echo $imageshow;









     }else{





echo "this formate is not supported";





}

}

?>

Ab Aap Is Program Ko Run Karwakar Dekh Sakte Ho.

Me Ummid Karta Hu Ki Apko Mere Post Achi Lagi Hogi Agar Apko Koi Problem A Rhe Hai To Aap Comment Section Me Puch Sakte Ho Thank You
Team Gajabwap Web In Hindi
 Also Read-
   Meta Tag Generator Tool Kaise Bnaye       

Previous
Next Post »
Thanks for your comment