Compress Image without loosing the QUALITY

<html>
<head>
<title>PHP Image</title>
</head>
<body>
<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”>
</form>
<?php
if(isset($_POST[‘compress’]))
{
@$uploaded_file=time().’.’.end(explode(‘.’,$_FILES[‘image’][‘name’]));

move_uploaded_file($_FILES[‘image’][‘tmp_name’],$uploaded_file);

$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);
}
else
{
die($img[‘mime’].’Is unsupported format!!!’);
}
$quality=$_REQUEST[‘quality’];
$output=’compressed-‘.$uploaded_file;
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 } ?>
<hr>
</body>
</html>

Advertisements

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.

 

<?php
            function readMail() {
                        $dns = “{imap.gmail.com:993/imap/ssl/novalidate-cert}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;
                        imap_close($openmail);
                        }
                        else {
                        echo “False”;
                        }
            }
?>

Detect the device using PHP

<?php

$tablet_browser = 0;

$mobile_browser = 0;

 

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

$tablet_browser++;

}

 

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

$mobile_browser++;

}

 

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_browser++;

}

 

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

$mobile_agents = array(

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

‘blaz’,’brew’,’cell’,’cldc’,’cmd-‘,’dang’,’doco’,’eric’,’hipt’,’inno’,

‘ipaq’,’java’,’jigs’,’kddi’,’keji’,’leno’,’lg-c’,’lg-d’,’lg-g’,’lge-‘,

‘maui’,’maxo’,’midp’,’mits’,’mmef’,’mobi’,’mot-‘,’moto’,’mwbp’,’nec-‘,

‘newt’,’noki’,’palm’,’pana’,’pant’,’phil’,’play’,’port’,’prox’,

‘qwap’,’sage’,’sams’,’sany’,’sch-‘,’sec-‘,’send’,’seri’,’sgh-‘,’shar’,

‘sie-‘,’siem’,’smal’,’smar’,’sony’,’sph-‘,’symb’,’t-mo’,’teli’,’tim-‘,

‘tosh’,’tsm-‘,’upg1′,’upsi’,’vk-v’,’voda’,’wap-‘,’wapa’,’wapi’,’wapp’,

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

 

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

$mobile_browser++;

}

 

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

$mobile_browser++;

//Check for tablets on opera mini alternative headers

$stock_ua = strtolower(isset($_SERVER[‘HTTP_X_OPERAMINI_PHONE_UA’])?$_SERVER[‘HTTP_X_OPERAMINI_PHONE_UA’]:(isset($_SERVER[‘HTTP_DEVICE_STOCK_UA’])?$_SERVER[‘HTTP_DEVICE_STOCK_UA’]:”));

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

$tablet_browser++;

}

}

 

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’;

}

 

?>

Edit HOST FILE

Hosts File

The Hosts file is like an address book. When you type an address like http://www.yahoo.com 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)
127.0.0.1 annoying-commercial.com
204.71.200.67 anypage.com

The IP-address 127.0.0.1 is the machine’s local address. This means that the first line blocks all contact with annoying-commercial.com 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 annoying-commercial.com won’t make it to your machine. This is a usual way of blocking unwanted advertising web pages.

By entering anypage.com in the address line, your browser will be directed to 204.71.200.67 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.