Your Ad Here

Tuesday, November 29, 2011

Automatic Post Creation with Wordpress, PHP, and XML-RPC


Automatic Post Creation with Wordpress, PHP, and XML-RPC

So, for those of you who read my last blog post, you might notice that I was having issues with a script I wrote to create a new post in Wordpress when it came time to upgrade the Wordpress code.  The SQL internals were modified, and I was inserting directly in to the database (yes, I know, I broke a cardinal rule).  I needed an alternative way to insert information in to the database that would be much more future-proof.  I remembered about XML-RPC.
It took me some time to find answers to questions I had about XML-RPC and the Wordpress’ API.  Wordpress comes with the ability to use XML-RPC, and AtomPub.  With regards to XML-RPC, it supports a few protocols:
  1. MetaWeblog
  2. Movable Type
  3. Blogger
  4. Wordpress’ own methods
Since there was little written documentation as to how to do this, I thought I’d share my findings.  Also, although the Blogger API was very easy to figure out and use, I’m not going to cover it here mainly because it doesn’t support the creation of a title field – something for my purposes were required.  (To access the blogger API, I used this class.)  I’m also only going to cover what’s necessary to create a new post for my own means, nothing more – hopefully it’ll get you on your way to how you’d like to use it.

One thing to note: In order for this to work, your version of Wordpress will have to have “Remote Publishing” enabled; depending on which protocol(s) you’ll be using, you’ll want to enable either “Atom Publishing Protocol” or “XML-RPC”, or both. This can be found (as of Wordpress version 2.7) under “Settings” and then “Writing”.
Let’s get to some nitty-gritty. The following XML-RPC methods are allowable with Wordpress (again, version 2.7):
Wordpress API:
  1. wp.getUsersBlogs
  2. wp.getPage
  3. wp.getPages
  4. wp.newPage
  5. wp.deletePage
  6. wp.editPage
  7. wp.getPageList
  8. wp.getAuthors
  9. wp.getCategories
  10. wp.getTags
  11. wp.newCategory
  12. wp.deleteCategory
  13. wp.suggestCategories
  14. wp.uploadFile
  15. wp.getCommentCount
  16. wp.getPostStatusList
  17. wp.getPageStatusList
  18. wp.getPageTemplates
  19. wp.getOptions
  20. wp.setOptions
  21. wp.getComment
  22. wp.getComments
  23. wp.deleteComment
  24. wp.editComment
  25. wp.newComment
  26. wp.getCommentStatusList
Blogger API:
  1. blogger.getUsersBlogs
  2. blogger.getUserInfo
  3. blogger.getPost
  4. blogger.getRecentPost
  5. blogger.getTemplate
  6. blogger.setTemplate
  7. blogger.newPost
  8. blogger.editPost
  9. blogger.deletePost
MetaWeblog API:
  1. metaWeblog.newPost
  2. metaWeblog.editPost
  3. metaWeblog.getPost
  4. metaWeblog.getRecentPosts
  5. metaWeblog.getCategories
  6. metaWeblog.newMediaObject
  7. metaWeblog.deletePost
  8. metaWeblog.getTemplate
  9. metaWeblog.setTemplate
  10. metaWeblog.getUsersBlogs
MovableType API:
  1. mt.getCategoryList
  2. mt.getRecentPostTitles
  3. mt.getPostCategories
  4. mt.setPostCategories
  5. mt.supportedMethods
  6. mt.supportedTextFilters
  7. mt.getTrackbackPings
  8. mt.publishPost
Wordpress also supports pingback, supposedly as an API. As for the AtomPub API, I don’t really understand that one yet, so if you want to find out what’s supported, you’ll want to look through the wp-app.php file found in your main Wordpress folder. The XML-RPC methods can be found in the xmlrpc.php file, also found in the main Wordpress folder.
As you can see, the Wordpress API is jam-packed with features – I believe most desktop applications that allow you to moderate your comments use the Wordpress API. Unfortunately, no “New Post” option for our needs. Dang. Because of this, and also because the Blogger API doesn’t support the creation of a title field in a new post, I decided to go with the MetaWeblog API. Technically speaking, MovableType and AtomPub are superior options to both Blogger and MetaWeblog from what I’ve been reading; regardless of that (possible) fact, I found it easy to work with the MetaWeblog API.
Let’s get to the code…
Umm…can PHP handle the transformation from data to the XML-RPC protocol of our choice automatically?
Unfortunately, no. However, the creators of Wordpress’ API features thought ahead. They packaged Wordpress with certain features and functionality (and classes) that can be utilized by us mere mortals to achieve our goals. Many of these libraries (such as the one we’ll use) were written by those not affiliated with Wordpress – so they took the legwork of finding good, well-written libraries for us.
We’ll be using the Incutio XML-RPC Library for PHP created by Simon Willison. You could download this yourself and include it in your script (note: commenter believes the official download to be corrupted), or you could just use what Wordpress already has in its folder structure, it’s the same thing with a few (pertinent) modifications and a different file name. (Wordpress uses it internally for some features since it works as a client and a server.)
The file is class-IXR.php, found in your wp-includes folder. So, to start out, we’ll create a PHP file that includes that script. We’ll also need to instantiate a new client object (to talk to the XML-RPC server – aka Wordpress). To find out what the address of your Wordpress XML-RPC server is (in order to instantiate the client), after you’ve enabled the XML-RPC remote publishing in your Wordpress settings, go to your Wordpress blog (any non-admin page) and view the source.
<link rel=”EditURI” type=”application/rsd+xml” title=”RSD” href=”http://www.example.com/xmlrpc.php?rsd />
You’ll want to take the URL from the HREF property of that line of code and place it in your browser. The rendered XML of the page gives us information as to the target URI for the protocol(s) we’d be using. If you’ll be using multiple protocols that use multiple targets, you’d have to target them each individually when making client calls. So, on to the fun stuff…
1include('/wp-includes/class-IXR.php');
2$client = new IXR_Client('http://www.example.com/xmlrpc.php');
This includes our XML-RPC library, allowing us to create a client connection. It then uses (defines) the target server access point for our client to access the APIs we aim to use. xmlrpc.php supports Wordpress, MovableType, MetaWeblog, and Blogger APIs all in one access point which makes it very easy if you want to use any or all four of them with the same IXR_Client object instantiation. Let’s build on that some more.
view sourceprint?
1include("../wp-includes/class-IXR.php");
3
4if (!$client->query('wp.getCategories','', 'admin','password')) {
5    die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
6}
7$response = $client->getResponse();
This extra code now tells our client to query our server for the Wordpress API’s “getCategories” method using the username of “admin” with a password of “password”. If any errors occur, the script will stop execution after printing the error codes and messages supplied by Wordpress’ API server. If it’s successful, the server’s response is stored in the $response variable.
Taking a step back, the getCategories method takes on 3 parameters. I left one blank simply because Wordpress (as of version 2.7) does not require the BlogID field (WPMU might, however). The 3 parameters are BlogID, Username, and Password. It will authenticate the user before allowing information to be returned.
The Wordpress API is quite easy (or at least for the getCategories method anyway), it simply returns a PHP structured array. An example print_r output from the $response variable would look like the following:
01Array
02(
03    [0] => Array
04        (
05            [categoryId] => 1
06            [parentId] => 0
07            [description] =>
08            [categoryName] => Uncategorized
09            [htmlUrl] => http://127.0.0.1/wordpress/category/uncategorized/
10            [rssUrl] => http://127.0.0.1/wordpress/category/uncategorized/feed/
11        )
12)
That’s pretty darn easy to break down to values we might need! Now, moving on, let’s add some code to create a new post.
1$content['title'] = 'Test Draft Entry using MetaWeblog API';
2$content['categories'] = array($response[1]['categoryName']);
3$content['description'] = '<p>Hello World!</p>';
4if (!$client->query('metaWeblog.newPost','', 'admin','password', $content, false)) {
5    die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
6}
7echo $client->getResponse();    //with Wordpress, will report the ID of the new post
This code sets up our desired blog title, the category we wish to use (in string format, do not use the ID value), the body of the blog post, and then queries the XML-RPC server. It calls the MetaWeblog API’s “New Post” method, and passes it some values. The parameters for this method are as follows:
Parameter Description
BlogID not used (yet)
Username the authenticated username that has permission to create posts via XML-RPC
Password the username’s associated password
Content the ARRAY of values that will be converted to XML by our XML-RPC library, and sent to Wordpress. There are a plethora of array key values that Wordpress supports for this data structure, but many of them are Wordpress specific. If you wish to remain more true to the specification, the ones I’ve shown are about all you’ve got.
Publish a boolean value to tell whether or not to immediately publish the post; in this example, it will create a draft entry, requiring someone to check it before publishing.

So we query the Wordpress XML-RPC server to create our new blog post, and if it’s successful, it returns the newly created blog posts’ ID field. The neat thing about this, is that (again, as of Wordpress version 2.7), if you wish to preview a blog post, you can use your Wordpress installation’s URL and adding a short query string to the end with this blog ID. For example, let’s assume this returned the ID of 3, the preview URL would then be:

http://www.example.com/?p=3
Pretty easy, huh? Here’s the full sample code without any breaks:
view sourceprint?
01<?php
02    include("../wp-includes/class-IXR.php");
03    $client = new IXR_Client('http://www.example.com/xmlrpc.php');
04
05    if (!$client->query('wp.getCategories','', 'admin',’password’)) {
06        die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
07    }
08    $response = $client->getResponse();
09
10    $content['title'] = 'Test Draft Entry using MetaWeblog API';
11    $content['categories'] = array($response[1]['categoryName']);
12    $content['description'] = '<p>Hello World!</p>';
13    if (!$client->query('metaWeblog.newPost','', 'admin',’password’, $content, false)) {
14        die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
15    }
16    echo $client->getResponse();    //with Wordpress, will report the ID of the new post
17?>
Hopefully having this documented somewhere will help someone out. I’ve used it at the work to allow librarians to upload exported XML New Item Record reports to the server, let it be processed, and then post the processed output to a Wordpress Draft where it can be reviewed for any irregularities or errors, and then posted for our public to see.

 

Thursday, November 24, 2011

Natural Language Full-Text Searches

By default, the MATCH() function performs a natural language search for a string against a text collection. A collection is a set of one or more columns included in a FULLTEXT index. The search string is given as the argument to AGAINST(). For each row in the table, MATCH() returns a relevance value; that is, a similarity measure between the search string and the text in that row in the columns named in the MATCH() list.
mysql> CREATE TABLE articles (
    ->   id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    ->   title VARCHAR(200),
    ->   body TEXT,
    ->   FULLTEXT (title,body)
    -> ) ENGINE=MyISAM;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO articles (title,body) VALUES
    -> ('MySQL Tutorial','DBMS stands for DataBase ...'),
    -> ('How To Use MySQL Well','After you went through a ...'),
    -> ('Optimizing MySQL','In this tutorial we will show ...'),
    -> ('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),
    -> ('MySQL vs. YourSQL','In the following database comparison ...'),
    -> ('MySQL Security','When configured properly, MySQL ...');
Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM articles
    -> WHERE MATCH (title,body) AGAINST ('database');
+----+-------------------+------------------------------------------+
| id | title             | body                                     |
+----+-------------------+------------------------------------------+
|  5 | MySQL vs. YourSQL | In the following database comparison ... |
|  1 | MySQL Tutorial    | DBMS stands for DataBase ...             |
+----+-------------------+------------------------------------------+
2 rows in set (0.00 sec)
By default, the search is performed in case-insensitive fashion. However, you can perform a case-sensitive full-text search by using a binary collation for the indexed columns. For example, a column that uses the latin1 character set of can be assigned a collation of latin1_bin to make it case sensitive for full-text searches.
When http://odesk-test-solutions.blogspot.com/2011/05/odesk-php-5-test-questions-and-answers.html href="http://odesk-test-solutions.blogspot.com/2011/05/odesk-php-5-test-questions-and-answers.html">MATCH() is used in a WHERE clause, as in the example shown earlier, the rows returned are automatically sorted with the highest relevance first. Relevance values are nonnegative floating-point numbers. Zero relevance means no similarity. Relevance is computed based on the number of words in the row, the number of unique words in that row, the total number of words in the collection, and the number of documents (rows) that contain a particular word.
To simply count matches, you could use a query like this:
mysql> SELECT COUNT(*) FROM articles
    -> WHERE MATCH (title,body)
    -> AGAINST ('database');
+----------+
| COUNT(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)
However, you might find it quicker to rewrite the query as follows:
mysql> SELECT
    -> COUNT(IF(MATCH (title,body) AGAINST ('database'), 1, NULL))
    -> AS count
    -> FROM articles;
+-------+
| count |
+-------+
|     2 |
+-------+
1 row in set (0.00 sec)
The first query sorts the results by relevance whereas the second does not. However, the second query performs a full table scan and the first does not. The first may be faster if the search matches few rows; otherwise, the second may be faster because it would read many rows anyway.
For natural-language full-text searches, it is a requirement that the columns named in the MATCH() function be the same columns included in some FULLTEXT index in your table. For the preceding query, note that the columns named in the MATCH() function (title and body) are the same as those named in the definition of the article table's FULLTEXT index. If you wanted to search the title or body separately, you would need to create separate FULLTEXT indexes for each column.
It is also possible to perform a boolean search or a search with query expansion. These search types are described in Section 11.9.2, “Boolean Full-Text Searches”, and Section 11.9.3, “Full-Text Searches with Query Expansion”.
A full-text search that uses an index can name columns only from a single table in the MATCH() clause because an index cannot span multiple tables. A boolean search can be done in the absence of an index (albeit more slowly), in which case it is possible to name columns from multiple tables.
The preceding example is a basic illustration that shows how to use the MATCH() function where rows are returned in order of decreasing relevance. The next example shows how to retrieve the relevance values explicitly. Returned rows are not ordered because the SELECT statement includes neither WHERE nor ORDER BY clauses:
mysql> SELECT id, MATCH (title,body) AGAINST ('Tutorial')
    -> FROM articles;
+----+-----------------------------------------+
| id | MATCH (title,body) AGAINST ('Tutorial') |
+----+-----------------------------------------+
|  1 |                        0.65545833110809 |
|  2 |                                       0 |
|  3 |                        0.66266459226608 |
|  4 |                                       0 |
|  5 |                                       0 |
|  6 |                                       0 |
+----+-----------------------------------------+
6 rows in set (0.00 sec)
The following example is more complex. The query returns the relevance values and it also sorts the rows in order of decreasing relevance. To achieve this result, you should specify MATCH() twice: once in the SELECT list and once in the WHERE clause. This causes no additional overhead, because the MySQL optimizer notices that the two MATCH() calls are identical and invokes the full-text search code only once.
mysql> SELECT id, body, MATCH (title,body) AGAINST
    -> ('Security implications of running MySQL as root') AS score
    -> FROM articles WHERE MATCH (title,body) AGAINST
    -> ('Security implications of running MySQL as root');
+----+-------------------------------------+-----------------+
| id | body                                | score           |
+----+-------------------------------------+-----------------+
|  4 | 1. Never run mysqld as root. 2. ... | 1.5219271183014 |
|  6 | When configured properly, MySQL ... | 1.3114095926285 |
+----+-------------------------------------+-----------------+
2 rows in set (0.00 sec)
The MySQL FULLTEXT implementation regards any sequence of true word characters (letters, digits, and underscores) as a word. That sequence may also contain apostrophes (“'”), but not more than one in a row. This means that aaa'bbb is regarded as one word, but aaa''bbb is regarded as two words. Apostrophes at the beginning or the end of a word are stripped by the FULLTEXT parser; 'aaa'bbb' would be parsed as aaa'bbb.
The FULLTEXT parser determines where words start and end by looking for certain delimiter characters; for example, “ ” (space), “,” (comma), and “.” (period). If words are not separated by delimiters (as in, for example, Chinese), the FULLTEXT parser cannot determine where a word begins or ends. To be able to add words or other indexed terms in such languages to a FULLTEXT index, you must preprocess them so that they are separated by some arbitrary delimiter such as “"”.
Some words are ignored in full-text searches:
  • Any word that is too short is ignored. The default minimum length of words that are found by full-text searches is four characters.
  • Words in the stopword list are ignored. A stopword is a word such as “the” or “some” that is so common that it is considered to have zero semantic value. There is a built-in stopword list, but it can be overwritten by a user-defined list.
The default stopword list is given in Section 11.9.4, “Full-Text Stopwords”. The default minimum word length and stopword list can be changed as described in Section 11.9.6, “Fine-Tuning MySQL Full-Text Search”.
Every correct word in the collection and in the query is weighted according to its significance in the collection or query. Consequently, a word that is present in many documents has a lower weight (and may even have a zero weight), because it has lower semantic value in this particular collection. Conversely, if the word is rare, it receives a higher weight. The weights of the words are combined to compute the relevance of the row.
Such a technique works best with large collections (in fact, it was carefully tuned this way). For very small tables, word distribution does not adequately reflect their semantic value, and this model may sometimes produce bizarre results. For example, although the word “MySQL” is present in every row of the articles table shown earlier, a search for the word produces no results:
mysql> SELECT * FROM articles
    -> WHERE MATCH (title,body) AGAINST ('MySQL');
Empty set (0.00 sec)
The search result is empty because the word “MySQL” is present in at least 50% of the rows. As such, it is effectively treated as a stopword. For large data sets, this is the most desirable behavior: A natural language query should not return every second row from a 1GB table. For small data sets, it may be less desirable.
A word that matches half of the rows in a table is less likely to locate relevant documents. In fact, it most likely finds plenty of irrelevant documents. We all know this happens far too often when we are trying to find something on the Internet with a search engine. It is with this reasoning that rows containing the word are assigned a low semantic value for the particular data set in which they occur. A given word may reach the 50% threshold in one data set but not another.

Friday, November 18, 2011

How to Create an Image in PHP An Introduction to the Image Functions in PHP

How to Create an Image in PHP
by deepak chauhan, http://wordpress-custom.blogspot.com/,

PHP makes it very easy to do many things needed on a website, among which is to create an image. The ability to generate an image in PHP can be useful if you want to do things like create CAPTCHA images, or even design a banner or logo on the fly the way some free blogging software do.

By the end of this tutorial, you will be able to create or modify an existing image using PHP, set the colours of its background, the text and the lines you draw, write text to that image, draw a line and set its thickness. You will also be able to either send that image to a web browser or to save it as a file. Armed with this basic foundation, you will also be able to knowledgeably explore further and perform more complex operations on images using PHP if you wish.
Prerequisites

Note: If you are here looking for an article on how to create banners or logos for your website, and not strictly for an article on how to write PHP scripts to generate such images, you may find my article on How to Create a Logo for Your Site the Quick and Easy Way more relevant.

   1.
      Basic PHP Knowledge

      I will assume that you already have some basic knowledge of how to write PHP programs. If not, you may wish to check out my basic PHP tutorial, How to Program in PHP.
   2.
      Your PHP Must Have Been Compiled with the GD Library

      For any of the functions listed here to be available, your PHP interpreter must have been compiled with the GD library. If you are using the PHP provided by a commercial web host, this is probably already provided as a standard feature.
   3.
      FreeType Must Be Compiled for TrueType Font Support

      If you want TrueType font support, your PHP must have FreeType support compiled into it as well.

An Introduction to Creating an Image from Scratch Using PHP

The easiest way to understand how to create an image is by looking at some sample code.

<?php
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, "wordpress-custom.blogspot.com",
  $text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>

The above code creates a 200x80 PNG image with a blue background and yellow text. It can be called from within your web page simply by referencing the php file. For example, if the PHP file that contains the above code is called myimage.php, then the HTML code to invoke it can simply be:
<img src="myimpage.php" alt="Image created by a PHP script" width="200" height="80">

Explanation of the Code

    *
      Creating the Image

      The first thing the code does is to call the imagecreate() function with the dimensions of the image, namely its width and height in that order. This function returns a resource identifier for the image which we save in $my_img. The identifier is needed for all our operations on the image.

      If the function fails for some reason, it will return FALSE. If you want your code to be robust, you should test for this.
    *
      Using Colours in PHP

      Before you can use any sort of colours in your image at all, you will need to allocate the colour. Colours are represented by three digits, known as the RGB value. The first digit denotes the red component, the second the green and the third blue, hence RGB, for Red-Green-Blue. These are the same colour values that you use for your web page as well as numerous other computer applications.

      Colours are allocated using the imagecolorallocate() function. This function will automatically fill the background of the image with the colour the first time you call it, as well as return an identifier for that particular colour. Subsequent calls to imagecolorallocate() will simply create a colour identifier for your colour, without affecting your image background.

      As you can see from the above code, my script allocates a blue identifier for the image, and in so doing, causes imagecolorallocate() to set the background to blue automatically. It also allocates a colour identifier for yellow and one for a shade of green. The latter two identifiers will be used later to write text and draw a line.

      imagecolorallocate() returns FALSE if the function fails for any reason.
    *
      Writing Text to the Image

      To write text to your image, you will need to use the imagestring() function. This function uses a set of built-in fonts to do the writing. The fonts have various sizes, ranging from 1 to 5, where 1 is the smallest font size and 5 the largest. The size of the font is specified in the second parameter to the function. In my example, I used font size 4.

      The third and fourth parameters to imagestring() specify the x,y coordinate for the top left hand corner of the text. In the case of the example above, my text will begin 25 pixels from the top edge of the image, and 30 pixels from the left.

      The fifth parameter is for the text to print, and the final parameter the colour of the text. This is the same colour that was allocated earlier using imagecolorallocate().
    *
      Drawing a Line and Setting the Thickness of the Brush

      The imageline() function can be used to draw a line to the image. To set the thickness of the brush used to draw the line, you may want to call the imagesetthickness() function as I did in my example. The numeric parameter to imagesetthickness() is the thickness of the brush in pixels. In my code, I set it to 5 pixels. If you don't call imagesetthickness(), the line will be 1 pixel thick.

      The imageline() function is called with the start and end coordinates of the line, in x,y format. In my code, the line starts from 30,45 and ends on 165,45. That is, it will be a horizontal line 45 pixels from the top, starting 30 pixels from the left edge and ending 165 pixels from that same edge. Since $line_colour was set to a shade of green earlier, the line will be green.
    *
      How to Output the Image

      Since the output of my example script is the image itself, I send an "image/png" content type header to the browser telling it that what follows are the bytes of a PNG image. The function imagepng() is then called to generate the necessary image from my $my_img image identifer. Since I called imagepng() without a second parameter, the function automatically sends its output to the browser. If you prefer to save your image, don't call the header() function to output the header, and call imagepng() with the filename of the image for its second parameter, like the following:
      imagepng( $my_img, "my_new_image.png" );

      Your image does not have to be a PNG image. You can use imagegif() or imagejpeg() to create GIF and JPG images respectively. You should of course send the correct content type header for the type of image you are creating. For example, a jpeg image should have a content type of "image/jpeg" while a gif image "image/gif". Note though that GIF support may or may not necessarily be compiled into the version of the GD library your web host is using, so if you're not sure, use one of the other file formats.
    *
      Freeing Resources

      On completion, the program releases the resources associated with the image by calling imagecolordeallocate() and imagedestroy(). I'm not sure if any of these calls are really necessary if your script is going to terminate immediately, since I don't know if PHP automatically cleans up all these resources on the termination of the script. I like to put those calls there for completeness.

Modifying an Existing Image

In most cases, creating an image from scratch is overkill. For most web purposes, you can usually design the basic background of your image using a normal image editor like Photoshop and only add any additional text or graphical elements that need to be dynamically drawn using PHP. This allows you to speed up your scripts and reduce the resource consumption on your web server. It also lets you create your picture using professional picture designing tools.

To use an existing GIF, JPEG or PNG image as a canvas on which you add additional elements, use one of the following functions instead of imagecreate().

imagecreatefromgif ( string $filename )
imagecreatefromjpeg ( string $filename )
imagecreatefrompng ( string $filename )

For example, if you created a GIF file called "mytemplate.gif", the function can be called as follows:
$myimage = imagecreatefromgif ( "mytemplate.gif" );

Like the basic imagecreate() function, these functions return FALSE if they fail to load the image for any reason.
Using TrueType Fonts

If you want to use a True Type font, you will need to use imagettftext() instead. For details on how to use this function, please consult the function's manual page on php.net.

You should note a few things, though, before using this function:

    *

      Check that your web host has compiled FreeType support into PHP before you rely on this function.
    *

      Find out whether your web host's PHP is using GD version 1 or 2. This affects a number of things, including the meaning of the font size parameter to the function (whether it means pixel size or point size).
    *

      Note that the coordinates for the text has a different starting point from imagestring(). That is, a coordinate like (say) 10,20 has a different meaning in the two functions.
    *

      Make sure the font you want exists on your web server. Remember that your web server is not the same as your computer. Just because a font like Arial exists on your computer does not mean that it exists on your server. If you have fonts that you created yourself, you may want to upload those to your web directory and use those instead. At least, that way, you have a guarantee that the font needed by your script exists.
    *

      The path setting to the font file is tricky, and depends on the version of the GD library your web server is using. One way around it is to specify the full path to the file on your server.

Monday, November 7, 2011

Simple Social Icons Widget with wordpress

Adds an available widget to list various social media profiles. The following social media sites are included by default:

* Facebook
* Twitter
* YouTube
* LinkedIn
* Google+
* FriendFeed
* Flickr

This plugin also includes a filter hook allowing you to extend the available services.

By default, this plugin outputs an unordered list (ul) with a class of social-icons-list. Each service is output as a list item (li) with the service name used as the HTML class attribute. Filters are available to allow you to change those HTML elements.

click here for download

Saturday, November 5, 2011

Google map








Elcom Systems Pvt Limited :: Location