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')