Removes Image Whitespace using PHP

To removes (trim) all white space around image (example on JPG), you can use this short code. How it’s work? It just a simple way. This script will find out where is the “WhiteSpace” stops, then it will copy everything inside the white space border.

<?php

//load the image! it's possible to open remote image from another website, just put full url on it!
$img = imagecreatefromjpeg("sample-image.jpg");

//find the size of the borders
$b_top = 0;
$b_btm = 0;
$b_lft = 0;
$b_rt = 0;

//top
for(; $b_top < imagesy($img); ++$b_top) {
  for($x = 0; $x < imagesx($img); ++$x) {
    if(imagecolorat($img, $x, $b_top) != 0xFFFFFF) {
       break 2; //out of the 'top' loop
    }
  }
}

//bottom
for(; $b_btm < imagesy($img); ++$b_btm) {
  for($x = 0; $x < imagesx($img); ++$x) {
    if(imagecolorat($img, $x, imagesy($img) - $b_btm-1) != 0xFFFFFF) {
       break 2; //out of the 'bottom' loop
    }
  }
}

//left
for(; $b_lft < imagesx($img); ++$b_lft) {
  for($y = 0; $y < imagesy($img); ++$y) {
    if(imagecolorat($img, $b_lft, $y) != 0xFFFFFF) {
       break 2; //out of the 'left' loop
    }
  }
}

//right
for(; $b_rt < imagesx($img); ++$b_rt) {
  for($y = 0; $y < imagesy($img); ++$y) {
    if(imagecolorat($img, imagesx($img) - $b_rt-1, $y) != 0xFFFFFF) {
       break 2; //out of the 'right' loop
    }
  }
}

//copy the contents, excluding the border
$newimg = imagecreatetruecolor(
    imagesx($img)-($b_lft+$b_rt), imagesy($img)-($b_top+$b_btm));

imagecopy($newimg, $img, 0, 0, $b_lft, $b_top, imagesx($newimg), imagesy($newimg));

//finally, output the image
header("Content-Type: image/jpeg");
imagejpeg($newimg);

?>

SEO Friendly for Search Result URL

Here is small code to make your WordPress Search Result more friendly for SEO (Search Engine Optimization). It will result http://www.shouthuns.com/search/find-something/ instead http://www.shouthuns.com/?s=find+something

Just put this code into top of the header of your themes. (Remember! It should be placed on first line on your header themes)

<?php
$src = strtolower(mysql_real_escape_string($_GET['s']));
$sclear = ereg_replace("[^ 0-9a-zA-Z]", " ", $src);
// Remove multiple spaces
while (strstr($sclean, "  ")) {
   $sclear = str_replace("  ", " ", $sclear);
}
// Replace spaces with a URL friendly + sign
$sclear = str_replace(" ", "-", $sclear);

// If valid then redirect to the URL rewritten search page
if ($sclear != '') {
   header( 'Location: http://www.shouthuns.com/search/'.$sclear.'/' );
}
?>

Before you try on your blog, please play around here first! Then, lets try on your blog now! And enjoy your new pretty searching result url!
Hopefully this article is useful :) Thanks for reading.

Guide To a Better Life

by DR. RANDY PAUSCH
Randolph Frederick “Randy” Pausch (October 23, 1960 – July 25, 2008) was an American professor of computer science and human-computer interaction and design at Carnegie Mellon University (CMU) in Pittsburgh, Pennsylvania.

He was a Carnegie Melon professor and was in his forties. Pausch died of complications from pancreatic cancer on July 25, 2008, but wrote a book “The last lecture”, one of the bestsellers in 2007. He gave an upbeat lecture titled “The Last Lecture: Really Achieving Your Childhood Dreams” on September 18, 2007, at Carnegie Mellon, which became a popular YouTube video and led to other media appearances. He then co-authored a book called The Last Lecture on the same theme, which became a New York Times best-seller. What a legacy to leave behind. In a letter to his wife Jai and his children, Dylan, Logan, and Chloe, he wrote this beautiful “Guide to a better life” for them to follow. May you be blessed by his insight.

Continue reading

About rel=”canonical” Tag

I just visited articlesbase.com and found the article that very interested for me. And I deserves to share this. Maybe it could be useful (especially for me). Hehe…!

The rel=”canonical” tag has has been around for a while, but there are still an abundance of people who may not have realised it exists or know precisely the reason for it’s introduction, but many search engine optimisers (SEO’s) will be the first to help explain the advantages it brings.

The rel=canonical tag can be found within the section of a website and can serve several uses. Such as being used to help solve duplication issues and also to refer to a page on another domain that is the original source of the content.

Continue reading