Reduce the image file size using PHP

Reduce the image file size using PHP:


$name = ''; $type = ''; $size = ''; $error = '';

   function compress_image($source_url, $destination_url, $quality) {

      $info = getimagesize($source_url);

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

          $image = imagecreatefromjpeg($source_url);

          elseif ($info['mime'] == 'image/gif')

          $image = imagecreatefromgif($source_url);

          elseif ($info['mime'] == 'image/png')

          $image = imagecreatefrompng($source_url);

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

          return $destination_url;


        if ($_POST) {

            if ($_FILES["file"]["error"] > 0) {

            $error = $_FILES["file"]["error"];


            else if (($_FILES["file"]["type"] == "image/gif") ||

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

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

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

            $url = 'C:/Users/admin/Downloads/compressed.jpg';

            $filename = compress_image($_FILES["file"]["tmp_name"], $url, 80);

        }else {

            $error = "Uploaded image should be jpg or gif or png";




    <title>Php code compress the image</title>
         <div class="error">
                 <?php if($_POST){ if ($error) {  ?>

<label class="error"><?php echo $error; ?></label>






           <fieldset class="well">

               <legend>Upload Image:</legend>

                   <form action="" name="img_compress" id="img_compress" method="post" enctype="multipart/form-data">




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



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







Get file content from a URL?

Get file content from a URL? $jsonData = json_decode(file_get_contents(‘×100&chd=t:60,40&chl=Hello|World&chof=json’)); However, if allow_url_fopen isn’t enabled on your system, you could read the data via CURL as follows: By using curl method:: $curlSession = curl_init(); curl_setopt($curlSession, CURLOPT_URL, ‘×100&chd=t:60,40&chl=Hello|World&chof=json’); curl_setopt($curlSession, CURLOPT_BINARYTRANSFER, true); curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, true); $jsonData = json_decode(curl_exec($curlSession)); curl_close($curlSession);

Send Message from Website in php

Send Message Using to user mobile phone from the website. $api_username = sms_api_username; $api_userpwd  = sms_api_pwd; $send_id = SMS_SEND_ID; $curl = “”; $msg = YOUR MESSAGE; $message = urlencode($msg);   $api_url = $curl . ‘?’ . “user=$api_username&pass=$api_userpwd&sender=$send_id&phone=$to&text=$message&priority=ndnd&stype=normal”; $sms = curl_init($api_url); ob_start(); $ex = curl_exec($sms); ob_end_clean(); curl_close($sms); return $ex;

Get contents using curl

$my_location_ip =’′; //syria $my_location_ip =’′;  $url = “{$my_location_ip}/json”; ##Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an ##array containing the HTTP server response header fields and content. function get_web_page( $url ) { $user_agent=’Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0′; $options = array( CURLOPT_CUSTOMREQUEST  =>”GET”,        //set request type … Read moreGet contents using curl