Tuesday, March 16, 2010

Auto Generation of Logo using php

Hi Folks,
This is something really interesting, to generate a logo automatically using php. Its quite simple and easy to do. Anyway Have a look at the code
 
if (!(file_exists("logophilip.png"))) // Checks file exist or not
{
$imgvalue = "Philip Tiju Abraham"; // Assign some text for the logo
$font_file = 'aladdin.ttf'; // Desired font, Make sure u have it in the same folder
$pic=ImageCreate(500,70); // Define the size of the image a x b
$col1=ImageColorAllocate($pic,230,197,156); // Background
$col2=ImageColorAllocate($pic,255,0,0); // Fontcolor
ImageFilledRectangle($pic,1,1,100,100,$col1);
ImageFtText($pic, 40, 0, 0, 50, $col2, $font_file, $imgvalue);
ImagePNG($pic,"logophilip.png"); // Thats it done...
ImageDestroy($pic);
}

Initially it checks the file exist or not, If the file already exist, its not necessary that we need to create again. Assign $imgvalue with the some test, here its "Philip Tiju Abraham". Also do select some font-face. Make sure you have the font in the same folder. $pic defines the size of the image. $col represents background color and $col2 represents font color. ImageFilledRectangle(), ImageFtText(), ImagePNG(), ImageDestroy() are function which renders the image.

Now to display the image is so simple...

Tuesday, March 2, 2010

How to replace innerHTML of a div using jQuery?

Most of you guys are familiar with innerHTML of Javascript. However this sorta stuff is quite old. Lets try with Jquery . Its quite simple, Lets see with a small example

Suppose we have a javascript like document.getElementById('mydivTag').innerHTML = 'Hello World';

To convert to Jquery its
$('#mydivTag').html('Hello World');

Thats it.. Its done..

When you deal with Value or text you can use
$('#mydivTag').text('Hello world')

Tuesday, February 9, 2010

Image Loading Effect while Image Actually Loads

Hi all, this is something really interesting. There are at times , where we need to insert loading effect while image Actually loads... Its quite simple... Lets see how its done...

1. Create a Loading image. You can create using ajaxLoad.info, and name it as loadingImage.gif
2. Create an area for Image. I prefer div tag as shown below

<div id="showloader" class="showloading" style="background: transparent url(spinner.gif) no-repeat center center;width: 500px;height: 500px;overflow: hidden;"></div>

3. Define a Javascript function as follow:

function putLoading(imageLink)
{
var img = new Image();
$(img).load(function ()
{
$(this).css('display', 'none');
$(this).hide();
$('#showloader').removeClass('showloading').append(this);
$(this).fadeIn();
}).error(function ()
{
// some error message
}).attr('src', imageLink);
}
4. Now just call the function putLoading(imageLocation);
5. Thats it..

======== Full Source Code:
<head>
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function putLoading(imageLink)
{
var img = new Image();
$(img).load(function ()
{ $(this).css('display', 'none');
$(this).hide();
$('#showloader').removeClass('showloading').append(this);
$(this).fadeIn();
}).error(function ()
{
// some error message
}).attr('src', imageLink);
}
</script>
</head>
<body>
<div id="showloader" class="showloading" style="background: transparent url(spinner.gif) no-repeat center center;width: 500px;height: 500px;overflow: hidden;"></div>

<script type="text/javascript">
putLoading('http://farm1.static.flickr.com/4024/4337935057_6c8e4aa993.jpg');
</script>
</body>




========


Example Link: Click here









Tuesday, January 26, 2010

Dynamic URL to static URL using .htaccess

Hi All..
Well this is my first post. For the last couple of years, I was wondering about domainname.com/username. Which is actually pretty cool. Usually we have a long hyperlink domainname.com/userdetails/search.php?user='username' . These are quite lengthy and its quite difficult to remember also. Lets see how its done.

1. Create a ".htaccess" file using Notepad , Notepad++ or any other Word editing softwares
2. Enter the following lines to code to it

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ domainname.com/userdetails/search.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ domainname.com/userdetails/search.php?user=$1

3. And save those changes and upload .htaccess under your root directory [ Depends upon the scenario ]
4. Create a search.php File [Replace this php file as u wish]
echo $_GET['user'];
?>
5. Thats it you are done with it .. Now you can use the following link
domainname.com/username

Couple of Examples:
www.www.indianmagicians.com/philiptijuabraham
www.indianmagicians.com/magicvideo/Magicianphiliptiju

Advantages of having Static sorta URLs over dynamic URLs are:
* Static URLs Rank better in Search Engines.
* Static URLs are always more friendlier looking to the End Users, Basically easy to remember.


Hopes this article helped you