Compress Image without loosing the QUALITY

<title>PHP Image</title>
<h1>Image Compression Using PHP</h1>
<form action=”” method=”post” enctype=”multipart/form-data”>
Upload an Image: <input type=”file” name=”image”><br>
Quality: <input type=”number” min=”30″ max=”100″ value=”50″ name=”quality”><br>
<input type=”submit” name=”compress” value=”Compress”>


$img = getimagesize($uploaded_file);

if ($img[‘mime’] == ‘image/jpeg’)
$image = imagecreatefromjpeg($uploaded_file);
elseif ($img[‘mime’] == ‘image/gif’)
$image = imagecreatefromgif($uploaded_file);
elseif ($img[‘mime’] == ‘image/png’)
$image = imagecreatefrompng($uploaded_file);
die($img[‘mime’].’Is unsupported format!!!’);
imagejpeg($image, $output, $quality);
<h3>Original Image (Size: <?php $osize=filesize($uploaded_file); echo round(($osize/1024),2).’ Kb’; ?>)</h3>
<img src=”<?php echo $uploaded_file; ?>”>
<h3>Compressed Image (Size: <?php $osize=filesize($output); echo round(($osize/1024),2).’ Kb’; ?>)</h3>
<img src=”<?php echo $output; ?>”>
<?php } ?>


Some Good Things

Yeah I know. What we tell is what we never do.
But still tell others some good things like
“Don’t get habituated to some things… which we can just tell and not apply for ourselves”

  • Eating junk food.
  •   Watching TV instead of going to the gym.
  •   Showing up to a job you hate everyday.
  •   Biting your nails.
  •   Smoking

They reflect on the below:

  • How in shape or out of shape you are?
  • How happy or unhappy you are?
  • How successful or unsuccessful you are?

Read Emails by PHP

Using IMAP you can read your inbox messages of your gmail account. Here I have shared code below.


            function readMail() {
                        $dns = “{}INBOX”;
                        $email = “Your Mail”;
                        $password = “Password”;
                        $openmail = imap_open($dns,$email,$password ) or die(“Cannot Connect “.imap_last_error());
                        if ($openmail) {
                                    echo  “You have “.imap_num_msg($openmail). ” messages in your inbox\n\r”;
                                    for($i=1; $i <= 100; $i++) {
                                                $header = imap_header($openmail,$i);
                                                echo “<br>”;
                                                echo $header->Subject.” (“.$header->Date.”)”;
                        echo “\n\r”;
                        $msg = imap_fetchbody($openmail,1,””,”FT_PEEK”);
                        $msgBody = imap_fetchbody ($openmail, $i, “2.1”);
                        if ($msgBody == “”) {
                        $partno = “2.1”;
                        $ msgBody = imap_fetchbody ($openmail, $i, $partno);
                        $ msgBody = trim(substr(quoted_printable_decode($msgBody), 0, 200));
                        echo $msg;
                        else {
                        echo “False”;

Detect the device using PHP


$tablet_browser = 0;

$mobile_browser = 0;


if (preg_match(‘/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i’, strtolower($_SERVER[‘HTTP_USER_AGENT’]))) {




if (preg_match(‘/(up.browser||mmp|symbian|smartphone|midp|wap|phone|android|iemobile)/i’, strtolower($_SERVER[‘HTTP_USER_AGENT’]))) {




if ((strpos(strtolower($_SERVER[‘HTTP_ACCEPT’]),’application/vnd.wap.xhtml+xml’) > 0) or ((isset($_SERVER[‘HTTP_X_WAP_PROFILE’]) or isset($_SERVER[‘HTTP_PROFILE’])))) {




$mobile_ua = strtolower(substr($_SERVER[‘HTTP_USER_AGENT’], 0, 4));

$mobile_agents = array(

‘w3c ‘,’acs-‘,’alav’,’alca’,’amoi’,’audi’,’avan’,’benq’,’bird’,’blac’,








‘wapr’,’webc’,’winw’,’winw’,’xda ‘,’xda-‘);


if (in_array($mobile_ua,$mobile_agents)) {




if (strpos(strtolower($_SERVER[‘HTTP_USER_AGENT’]),’opera mini’) > 0) {


//Check for tablets on opera mini alternative headers


if (preg_match(‘/(tablet|ipad|playbook)|(android(?!.*mobile))/i’, $stock_ua)) {





if ($tablet_browser > 0) {

// do something for tablet devices

print ‘is tablet’;


else if ($mobile_browser > 0) {

// do something for mobile devices

print ‘is mobile’;


else {

// do something for everything else

print ‘is desktop’;





Hosts File

The Hosts file is like an address book. When you type an address like into your browser, the Hosts file is consulted to see if you have the IP address, or “telephone number,” for that site. If you do, then your computer will “call it” and the site will open. If not, your computer will ask your ISP’s (internet service provider) computer for the phone number before it can “call” that site. Most of the time, you do not have addresses in your “address book,” because you have not put any there. Therefore, most of the time your computer asks for the IP address from your ISP to find sites.

To find the location of hosts file, look at the following location for each operating system.

Win95/98 hosts file location:
Windows 95/98/Me c:\windows\hosts

Win2k hosts file location:
Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc\hosts

XP hosts file location:
Windows XP Home c:\windows\system32\drivers\etc\hosts

To open a hosts file, right click on the file and select Open. You will be prompted to choose a program to open the file with. Select Notepad.

The hosts file consists of an IP-address to which the browser is to go to when the domain name after is entered in the browser address line.
Ex: (from a hypothetical hosts file)

The IP-address is the machine’s local address. This means that the first line blocks all contact with by linking it to the computer self. This will give the browser a busy signal, and it will give up trying to find it. Hence any links to won’t make it to your machine. This is a usual way of blocking unwanted advertising web pages.

By entering in the address line, your browser will be directed to which is the Yahoo directory.

Editing the Hosts file on Windows Vista and Windows 7

1. Open Notepad with Administrative privileges by clicking Start, All Programs, Accessories, and then right-click Notepad and select to open as Administrator.

2. Now that Notepad is open with Administrative privileges browse to (C:\Windows\System32\drivers\etc) in Notepad and open the hosts file.

Now you can edit and save the hosts file.