Thursday, November 25, 2010

Convert Image In To Text Using PHP Script

Ever wanted to create those text made roses and heart shapes that you see in Facebook and Myspace? You might be wondering how they create such. However there are some websites that does the job, you may still be curios to do it by yourself. They convert your image file in to a text which exactly renders as an image. If you are still unclear what I am talking about then see how this JPEG image is manipulated to text.



First view the demo here.

You might be surprised that this manipulation can be done just by PHP code not more than 30 lines.
We’ll do this just by a PHP code.

Let me show you how can you use PHP imagecreatefromjpeg() function to manipulate the pixeleted image in ASCII character form.
First of all let’s summarize what we’ll do.

First, we’ll create a variable pointing the location of the image. Now we’ll feed that image location variable to imagecreatefromjpeg() function like this:

$locate= 'http://website.com/image.jpg';
$image = imagecreatefromjpeg("$locate");

Now the imagecreatefromjpeg() function manipulates the image details like RGB color coding, white pixels etc.

Since our PHP code have the details of the image, we’ll add conditional tag what to do next if the image have been manipulated by the imagecreatefromjpeg() function. In the conditional statement we’ll fetch the RGB value, get the brightness situation and finally put a ASCII character along with the brightness.

What our code needs to do is loop through each row in the image, and within each row it needs to also loop through each column. This means we’re accessing each pixel one-by-one, which is what we need. Then, for each pixel in the image, we need to grab the red, green, and blue color values of the pixel, add them all together.

By default, we’ll define the ASCII keys as array for the brightness. For example, [@#+*;:, ] we’ve increasing brightness symbol from @ which denotes the extreme dark and a white space at last which denote extreme white.

The darker part will be replaced by @ and white part will be replaced by white space, while other characters will denote the level of brightness in eight characters.

Have a look at the PHP code below:

echo '

';

$asciichars = array("@", "#", "+", "*", ";", ":", ",", ".", "`", " ");

$width = imagesx($image);

$height = imagesy($image);

for($y = 0; $y < $height; ++$y) {

for($x = 0; $x < $width; ++$x) {

$thiscol = imagecolorat($image, $x, $y);

$rgb = imagecolorsforindex($image, $thiscol);

$brightness = $rgb['red'] + $rgb['green'] + $rgb['blue'];

$brightness = round($brightness / 85);

$char = $asciichars[$brightness];

echo $char;

}

echo "\n";

}
echo '

';

}

And finally we’ll print the result.

The final code will be like this:

$locate= ‘http://website.com/image.jpg’;

$image = imagecreatefromjpeg("$locate");

if ($image) {

echo '

';

$asciichars = array("@", "#", "+", "*", ";", ":", ",", ".", "`", " ");

$width = imagesx($image);

$height = imagesy($image);

for($y = 0; $y < $height; ++$y) {

for($x = 0; $x < $width; ++$x) {

$thiscol = imagecolorat($image, $x, $y);

$rgb = imagecolorsforindex($image, $thiscol);

$brightness = $rgb['red'] + $rgb['green'] + $rgb['blue'];

$brightness = round($brightness / 85);

$char = $asciichars[$brightness];

echo $char;

}

echo "\n";

}

echo '

';

}

?>

Just copy it to your notepad and save it as image.php. Before saving define the location of picture.
You can also create a form to specify the location of the image and input the form value in $locate variable.
Posibilities are endless, who knows one can start his own website only with this script.
Again, view the demo here.

Tuesday, November 23, 2010

Learn Real Hacking With Real Hacking Game

If you are very new in hacking world, before going to the article, I suggest you to read Learn How To Hack With The Hacker’s Underground Handbook before reading further article.

If you are already known to the hacking world then, welcome to the virtual simulation world of hacking environment.

If you really need some easy platform to practice hacking then I think this article will be a great help for you. Yes I am talking about the real hacking game, Hack The Game.

HackTheGame is a free 1MB file game which will introduce you to the real hacking word.

The real hack able DOS environment makes you feel like that you have finally accessed to US Defense system.

The game becomes much more interesting and fun because of the addition of sounds. The sounds includes typing and several warning announcement.

The user interface of HackTheGame is very friendly and easy. Just open the program and select your language, input any ID you may like.

There are several missions of this game. You’ll get the briefing of each mission in your inbox.

The mail itself includes several hints and processes.

If you find sounds irritating then, you can go to settings menu and disable sounds. But I bet you, enabling sounds makes your game play experience very easy.

I bet you’ll love this game.

No installation is needed to run this game and it is obviously safe to use because it utilizes local files which in game play acts as a remote files. You don’t have to worry about your security. If you doubt it, then play it offline.

This game can be downloaded from here, HackTheGame.

Sunday, November 21, 2010

Login to Windows Live Messenger using any email account

Everybody has hotmail account, don’t they? I created my first email account in Hotmail 9 Years ago. MSN Hotmail and Yahoo were the heroes of free web mail system at that time, and still they are. Later in 2004, Gmail showed up with large email space capability. The only famous messenger was ICQ. Later Hotmail introduced MSN messenger, now they’ve named it Windows Live Messenger which we are using at the current date.

Since you have lots of email account in several domains, it is necessary to run their own messenger. Try to log in using your Gmail or Yahoo account, messenger will return with 80048821 error saying, Windows Live ID or Password is incorrect, because Gmail is not domain of MSN.

But after following this trick, you won’t have to open install multiple web messengers. Let met guide you how you can access Windows Live Messenger using your own email account which is not a domain of MSN. You’ll be able to login using Gmail, Yahoo or any email account you have.

Go to http://www.passport.net, after the page is loaded scroll down to Sign up today. As shown in figure, click on Get Started Now link of Use an e-mail address you already have.

Now fill up the form with the email address you want to sign up using Windows Live Messenger and other necessary information and click on Continue button.

In next page, retype the email address as shown in the left.

Now, it will inform you to confirm your account in next page. Click on Continue button.

Now you may close the page.

Next, we’ll need to confirm our mail. They’ll send you a confirmation link in the email address that you’ve specified earlier during form fill up.

Login to your Gmail or any email account using respective domain and look for Verification mail from Windows Live Team.

Read the mail properly and click on the confirmation link

Wait a minute! Confirmation is not over yet, you’ll have to login with the new email address and password that you’ve filled up earlier in the form.

For the successful confirmation, you’ll be welcomed to this page.

Now try to login using your Gmail or any email account from Windows Live messenger.

Note: If you have not confirmed properly you’ll be notified.

If you see this screen at the top of your Windows Live Messenger, make sure that you’ve confirmed properly.

Wednesday, November 17, 2010

Learn to hack from Real Hacking game for those who want

If you are very new in hacking world, before going to the article, I suggest you to read Learn How To Hack With The Hacker’s Underground Handbook before reading further article.

If you are already known to the hacking world then, welcome to the virtual simulation world of hacking environment.

If you really need some easy platform to practice hacking then I think this article will be a great help for you. Yes I am talking about the real hacking game, Hack The Game.

HackTheGame is a free 1MB file game which will introduce you to the real hacking word.

The real hack able DOS environment makes you feel like that you have finally accessed to US Defense system.

The game becomes much more interesting and fun because of the addition of sounds. The sounds includes typing and several warning announcement.

The user interface of HackTheGame is very friendly and easy. Just open the program and select your language, input any ID you may like.

There are several missions of this game. You’ll get the briefing of each mission in your inbox.

The mail itself includes several hints and processes.

If you find sounds irritating then, you can go to settings menu and disable sounds. But I bet you, enabling sounds makes your game play experience very easy.

I bet you’ll love this game.

No installation is needed to run this game and it is obviously safe to use because it utilizes local files which in game play acts as a remote files. You don’t have to worry about your security. If you doubt it, then play it offline.

This game can be downloaded from here, HackTheGame.

Monday, November 15, 2010

How to create a wordpress Upcomming Events Widget- A step by step tutorial

This Wordpress tutorial is targeted to those who are struggling for being a good Wordpress developer. This tutorial will be delivered in simplest term so that a newbie can easily understand what is going on the screen. After following this step by step tutorial, you’ll able to do following things:

  1. Create a very basic Wordpress widget acceptable for even version Wordpress 3.0.1
  2. Create a basic upcoming events widget which lists the scheduled articles.

Wordpress is created in PHP. So, you must know the basic coding knowledge in PHP. Except default Wordpress widgets, you’ll need to create a separate plugin to add separate thirdparty widget to your wordpress blog.

We are going to create a basic plugin first.

Before we start the coding part, lets go to Wordpress Admin panel and explore through the plugin control panel.

To go to Plugin control panel, at the left sidebar, click on Plugins.

This is the place where you can activate/disactivate or install/remove plugins. By default Wordpress stores all the plugin files in wp-content/plugin folder.

For each plugin, you can see various definations. The basic definations needed are, plugin name, plugin URI, description, author name, version and author’s website.

These all will be defined inside the plugin php code.

Let me show you how you can set the details of plugin and start the coding for new plugin.

Open up notepad, a very simple yet powerful text editor by Microsoft.

We must begin every PHP code by

/*

Plugin Name: Comming up

Plugin URI: http://www.hackspc.com

Description: Up comming posts

Author: suraZ Kayastha

Version: 1.0

Author URI: http://youcanhack.blogspot.com

*/

These are actually PHP comments held between /* */ but wordpress fetches these section for details about the plugin.

Wordpress Plugins are all about PHP functions (the division of codes that work for specific part).

Lets see what we can do with the functions to create a plugin that will load a new widget.

/* Function that will deliver all the necessary code contents in the sidebar */

function commingup_widget() {}

/* Function that is called by wordpress when the plugin is activated. It registers new widget called Coming Up */

function init_commingup(){

register_sidebar_widget("commingup", "commingup_widget");

}

/* Tells WordPress to call init_commingup when plugin is loaded */

add_action("plugins_loaded", "init_commingup");

Confused? Let me clear you what those codes do. The first function, commingup_widget(), here is what will be displayed on the sidebar. Whatever HTML/PHP code you put here will be displayed as a sidebar widget. It can be links, texts or any other dynamic contents.

The second function, init_commingup(), is called by WordPress if the plugin is activated. It calls a WordPress function that will register a new widget which will be called “Coming Up” which will call our new widget.

Add action just tells WordPress to call the second function when the plugin is loaded.

That is done, you’ve successfully created a plugin that will deliver a new blank widget.

You may be wondering how you can place dynamic contents in your newly created widget plugin.

This is so simple to do if you know little bit PHP and HTML coding.

Now let’s forget what we’ve done above.

And let me show you the idea to get things ready for your widget.

Consider the following loop that will show the posts that are marked as scheduled posts.

status=future'); ?>

else: ?>

No future events scheduled.

The above code is just a basic posts loop that we have in your index.php page. Only the difference is, it is modified to view only title and scheduled date. Post_status=future makes is so much special. Hence all the posts except scheduled one are filtered out.

You can directly put the above code in any part of index.php. But, we are creating a widget right?

So we’ll modify that code to fit as a widget.

Here is the modified part of it:

echo '

  • Comming up

    ';

    echo '

      ';

      query_posts('showposts=10&post_status=future');

      if ( have_posts() ) : while ( have_posts() ) : the_post();

      echo '

    • '; the_title(); echo '

      ';

      echo ''; the_time('j F Y'); echo '

    • ';

      endwhile;

      else: echo '

      No future events scheduled.

      ';

      endif;

      echo '

  • ';

    We’ll place the above code in function commingup_widget().

    When we combine the description code and the functions we’ll get the following setup of code.

    /*

    Plugin Name: Comming up

    Plugin URI: http://youcanhack.blogspot.com

    Description: Up comming posts

    Author: suraZ Kayastha

    Version: 1.0

    Author URI: http://youcanhack.blogspot.com

    */

    function commingup_widget() {

    echo '

  • Comming up

    ';

    echo '

      ';

      query_posts('showposts=10&post_status=future');

      if ( have_posts() ) : while ( have_posts() ) : the_post();

      echo '

    • '; the_title(); echo '

      ';

      echo ''; the_time('j F Y'); echo '

    • ';

      endwhile;

      else: echo '

    • No future events scheduled.

      ';

      endif;

      echo '

  • ';

    }

    function init_commingup(){

    register_sidebar_widget("commingup", "commingup_widget");

    }

    add_action("plugins_loaded", "init_commingup");

    ?>

    See that? All the codes are enclosed in . Now all we need to do is save it as PHP file. Name it anything you want, I named it commingup.php.

    Upload it to wp-content/plugins/commingup.

    Go to plugin control panel in wordpress and activate it.

    Now navigate to widget control panel, Right sidebar > Appearance > Widgets.

    There you go, you’ll see the widget that you’ve just created.

    Click and drag it to the sidebar.

    Now reload your Wordpress website. If you have any scheduled post then it will list it as an upcoming event.

    If nothing is scheduled then it will print “No future events scheduled”.

    If you have any confusion, then comment us. We’ll have full support for this widget in our blog.

    Sunday, November 14, 2010

    View PSD and other image files without installing Photoshop

    Yesterday, I requested my friend to send me the snapshot of the PSD file of the Wordpress design. But he claimed that his Photoshop CS2 has expired. He thought of going to his friend and copying the snapshot and again sending back to me. Photoshop Document itself was large size, therefore I asked for the snapshot. If I was going to accept his idea, then I would have to wait whole day for just a snapshot.

    Rather I suggested him certain idea to view PSD files without the need of Photoshop. And that is what I want to share with my visitors as well.

    With IrfanView, a 1.3 MB image viewing freeware utility, you can open almost all the images without need of any high level software. Here is a list of image files that I can open.

    IrfanView is a freeware utility, licensed under End User License Agreement (EULA).

    It is not only a viewer; rather you can edit the pictures there. Basically it supports cropping, cut, paste, copy, drawing tools, eraser tools etc. IrfanView is plug-in enabled, that means they have plug-in to make it more accessible and useful.

    Click here to download IrfanView

    This is guest post from suraZ. His other interesting posts can be read on You Can Hack and Hacktutors blog.

    Saturday, November 13, 2010

    Only Retrieve First Image Of The Post In Mainpage If It Exists – Wordpress Hack

    I am going to apply a small hack to the trick suggested by wprecipes.com to display the first image from the post in a mainpage.

    Let’s summarize what they’ve done.

    First they’ve created a function that retrives the first image of the post if the image is not found, then it will show default.jpg image from the defined location.

    function catch_that_image() {

    global $post, $posts;

    $first_img = '';

    ob_start();

    ob_end_clean();

    $output = preg_match_all('/"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);

    $first_img = $matches [1] [0];

    if(empty($first_img)){ //Defines a default image

    $first_img = "/images/default.jpg";

    }

    return $first_img;

    }

    Code exactly copied from wprecipes.com

    The above code snippet is to be copied in functions.php file located at the themes root folder. If it doesn’t exists, then you can create one using notepad, and paste the above code enclosed in following format:

    Wprecipes.com’s function code goes here

    ?>

    Now to load the image anywhere in your main page or any other page just places the following code within the posts loop.

    The above PHP function code must like somewhere near to or

    Consider it in the following example loop.

    " rel="bookmark" title="Permanent Link to ">

    by

    " />

    You’ll get following type of screen in your post loop.

    The upper post contains the first image of the post. The lower content is not showing any images rather than a alternate tag. It is because we don’t have any image in the second post, by default from functions.php, functions will be redirected to no image and browser will try to load default image. If browser is unable to find /images/default.jpg, which we have specified in functions.php it will show no image but alternative title, you must upload default.jpg in the specific location to get the default image.

    But using default image might not be dynamic and useful if most of your post doesn’t contain any images. Then we’ll have to seek extra tweaks to show nothing in place of default image.

    Let me show you how can you accomplish this using extra function.

    First, we’ll create a function that will scan for presence of any image in the specific post, then we’ll define what it must do if image is there and what it must do if image is not there. It can be accomplished by using conditional tags.

    Here is the function to scan image, add this in functions.php just above, ?> (i.e. exactly above the PHP code end tag)

    function image_scan( $args = array() ) {

    if ( !$post_id )

    global $post;

    preg_match_all( '|?>|i', $post->post_content, $matches );

    if ( isset( $matches ) ) $image = $matches[1][0];

    if ( $matches[1][0] )

    return array( 'image' => $image );

    else

    return false;

    }

    Now we’ll use PHP conditional tag in index.php or any page where we want this to take effect on.

    Show image

    The final code will be like this after applying the the image_scan condition.

    " rel="bookmark" title="Permanent Link to ">

    by

    " />


    Now you’ll have only thumbnails of first images if it exists, otherwise it shows no image.