Reduce the image file size using PHP

Reduce the image file size using PHP:

<?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";

        }

        }

?>



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

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

            <?php

            }

         }

       ?>

       </div>

           <fieldset class="well">

               <legend>Upload Image:</legend>

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

                       <ul>

                           <li>

                               <label>Upload:</label>

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

                               </li>

                           <li>

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

                           </li>

                       </ul>

                  </form>

           </fieldset>

     </body>

</html>

Get file content from a URL?

Get file content from a URL?

$jsonData = json_decode(file_get_contents('https://chart.googleapis.com/chart?cht=p3&chs=250x100&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, 'https://chart.googleapis.com/chart?cht=p3&chs=250x100&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 Bhashsms.com to user mobile phone from the website.
 
$api_username = sms_api_username;
$api_userpwd  = sms_api_pwd;
$send_id = SMS_SEND_ID;

$curl = "http://bhashsms.com/api/sendmsg.php"; 

$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 ='95.212.128.0'; //syria

$my_location_ip ='27.49.37.170'; 

$url = "http://ipinfo.io/{$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 post or get
CURLOPT_POST           =>false,        //set to GET
CURLOPT_USERAGENT      => $user_agent, //set user agent
CURLOPT_COOKIEFILE     =>”cookie.txt”, //set cookie file
CURLOPT_COOKIEJAR      =>”cookie.txt”, //set cookie jar
CURLOPT_RETURNTRANSFER => true,     // return web page
CURLOPT_HEADER         => false,    // don’t return headers
CURLOPT_FOLLOWLOCATION => true,     // follow redirects
CURLOPT_ENCODING       => “”,       // handle all encodings
CURLOPT_AUTOREFERER    => true,     // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
CURLOPT_TIMEOUT        => 120,      // timeout on response
CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
);
$ch      = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err     = curl_errno( $ch );
$errmsg  = curl_error( $ch );
$header  = curl_getinfo( $ch );
curl_close( $ch );
$header[‘errno’]   = $err;
$header[‘errmsg’]  = $errmsg;
$header[‘content’] = $content;
return $header;
}
$getContents = get_web_page($url);

$getContents_jsonData = $getContents['content'];

$getContents_jsonDecoded = json_decode($getContents_jsonData);

echo "<pre>";

print_r($getContents_jsonDecoded);

echo "</pre>";