Monthly Archives: November 2006

Phillips Darth Vader Commercial

Very funny.

Phillips Darth Vader Commercial


Useful functions

Checking the statistics of the blog, I noticed the user were searching for some information I’ve put time ago.

As all my information were a mess, I decide to delete all the old posts and start again (sorry for that).

I’ve noticed the people were looking for two similar things:

  1. Convert between image formats in PHP
  2. Desaturate an image (and other functions)

I will talk on this and create a new category: Code Snippets

Convert between image formats in PHP (converting png images into jpeg, gif)

First you need the php-gd extension installed, if you write:

You need to search something like this:
PHP GD Installation

With this, you will know you have php-gd2 (version 2 is surely better and the php5 version of php-gd2 seems to be better with new filters).
You also know with this, you can save on GIF, JPG, PNG, WBMP and XBM, and also you can handle Freetype Fonts (TTF)

To convert a file is really easy:

$image_png = "your_image.png";
$image_output = "your_output_image.jpg";
$image = imagecreatefrompng($image_png);
imagejpeg($image, $image_output);

So simple!, if you want to open a jpeg and save into gif, you need only this:

$image_jpeg = "your_image.jpg";
$image_output = "your_output_image.gif";
$image = imagecreatefromjpeg($image_jpeg );
imagegif($image, $image_output);

Easy, all the php-gd2 which handle with formats ends with the format type (jpeg, gif, png, wbmp, etc).

More information:

Desaturate Image

One of the most common changes to an image is to set as grayscale, to make this, you need to convert each possible (256^3 colors) into a 256 color (which is the grayscale).
In fact, if you put the same color into the three channels (RGB) you will have a grayscale image.

To make this, there are usual paths:

  1. Set the color to the average of the three colors: (R + G + B) / 3
  2. Convert through decimals to each color, for example: R*0.299 + G*0.587 + B*0.114, you need to assure the sum of the decimals make one, or you are going to have black “holes” (0.299 + 0.587 + 0.114 = 1.0)
  3. Desaturate, the RGB model is a computer-friendly model; but the classical model for colors is HSV which means: Hue, Saturation, Value.
    In this model, you have a cone, like the image of below, the hue is the “color” in fact (a 360 continous color), the Saturation means how much pigmented will be the color (0 means no pigment and 1.0 means full pigment) and the value is how much light the color will have (0 means black and 1 means white).
    So Desaturate in fact is eliminate the saturation value, since it represents the pigmentation, to achieve this you need to convert into HSV model, make 0 to Saturation value, and convert again into RGB model and save.

HSV Cone Model

The most used is option 2), since a good example is the Photoshop Mix Channels filter, you can make get your own values to mix the colors from Photoshop.

To achieve this in PHP, I’ve found a good way in posted by

function imagetograyscale($im)
if (imageistruecolor($im)) {
imagetruecolortopalette($im, false, 256);

for ($c = 0; $c < imagecolorstotal($im); $c++) {
$col = imagecolorsforindex($im, $c);
$gray = round(0.299 * $col['red'] + 0.587 * $col['green'] + 0.114 * $col['blue']);
imagecolorset($im, $c, $gray, $gray, $gray);

What this filter does is simple convert each color in the image for the new gray value, in a traditional way, you need to go to each pixel and convert to the new color.

In a later post I will tell you how to change to HSV model and how to perform really desaturation.

More Information:
HSV Model:


Curso Hacker – How to become a hacker!

I always laugh when most people talk about “hackers”; the “hackers” are a kind of urban myth; since everyone knows one and everyone dreams to be one.

Notice how I use “hackers” word, the “hackers” are those defined by media and person without knowledge; my definition by those are simple: Script Kiddies.

Media most common (and childish) definition is separate into two groups: white hat “hackers” and black hat “hackers” (good and bad) and to make more special the term “hacker” they also put other colors to hats, like red, blue, etc, etc, etc.

Most people definition of “hacker” is  a Script Kiddie, if you don’t know a Script Kiddie is just a person with two abilities:
1) Can fetch some basic information of the system and
2) Can search on internet for exploit scripts.

Time ago I was suffering since I installed Joomla and I didn’t check any updates, a exploit was found which allow to execute shell commands, after checking my logs, I notice the “hacker” downloaded a program which stop the web server; the data was never stoled or in danger (even with the Joomla security hole it was easy to fetch some information), and the program was a kind of brute-force DOS against the web server (in the localhost), so the web server will stop working.

In my university was a very common topic the script kiddies, since our student server was attacked frequently to make the system stop working, even the people close to the administrator (and girlfriends and even other friends of the friends) knew the root password, and they tried exploit script just to test how safe the server was (!).

In a dedicated server in which I’m working there is always logs like: “Failed authentication trying to login as fred, john, etc”, some people were running automated logins (best way to hack =) )

Today I found a site: Curso Hacker (Hacker Course in spanish), they said to give you all the tools and information to become a “hacker“; you just need to pay a minimum of $49 USD at month to access all the content.

In the maximum price ($99 USD) you can talk with a professor in friday night (I imagine a 14 years old teen eating pizza while his mother try to make him go to sleep).

The course  is full of “hacker” jargon, like cracking wep keys. The fact is they only will show you how to be a “hacker“, this is a script kiddie exploiting in ICQ/IRC and similar; in my little knowledge I haven’t seen anybody which become a famous hacker, not even considered a serious hacker; but pay that money and surely you will be the most wanted of your neighborhood.

I remember the last linux congress here in my city, a group described  as: “teenages precocious” (that’s the spanish translation, man I’m learning english =) ), teached some of this kind of techniques, to all the people I talk on those days, they only knew him because the last year they fire up the bed of the hotel and they were drinking and noisy all the nights.

In their course they teach how to send fake emails or enter in a non-protected user session, like when somebody create the www user and leave with a password and /bin/bash as default shell (!), again this is a gossip I heard >=).

I forgot, if you know a bit of spanish, check the forum of the Curso Hacker (there is a link on almost every page to show how grateful are the users to learn all this power).
The forum is full of  “Man I’m  a starter and I know more than Neo in Matrix Revolutions”, or “Thanks to all the people who were hacking with me this night, W3 4ul3z”.
Do you want to be recognized, it’s very easy: LEARN HOW TO PROGRAM, if you are a programmer is more easy to find bugs, a bug can be converted in a security hole, a security hole can be converted into a root entry into a system, or things like that, of course that if you are a black hat “hacker” (according media), if you are a white hat, then you will notice a security expert group and surely you will be recognized among them; and not by replacing c‘s by k‘s or s‘ by z‘s, or mix number and letters ;-)


Mathematic Lessons

Today I checked a project proposal on, there have been a bit of time since I was using it (the last time was helping a recurring client with his site).

When I found ScriptLance seemed to be more good paying projects than GetAFreelancer (another site where I’m getting job as Freelancer); at the end, I’ve seen very few posts lately on ScriptLance and much, much more in GetAFreelancer; of course always has a lot of projects; but all were with a maximum budget of $300, now it’s more easy to find projects of $300-$1500 as budget and even are rare more larger projects this seems to be changing.

Well I’ve heard that ScriptLance system is a commercial script (in Perl I think) and recently they started to enhance it; from 4-6 months ago I’ve seen a more harder development and it’s more usable and useful.
Recently I noticed the overall ranking (also know as the top programmers), I’ve seen people having more than 200 reviews and the user profile I noticed had only 6, so I wanted to see how they calculated the ranking; I notice they put points to each freelancer, then I read how they calculated this points (since in the first 25 was people with less than 10 reviews), the description on how they calculate the ranking is the following:

How are rankings and points determined?

Points are calculated using a mathematical formula that considers, for each project a freelancer has participated in, the rating given to the freelancer and the amount of the bid. The reviewer’s own total rating also affects, although much less, the points awarded to the freelancer.

Points are calculated seperately for each project category, as well as overall. Rankings are determined based on those points by comparing the points to other freelancer’s scores.

Please note that rankings don’t necessarily represent the skills of the programmers compared to others, but is more of an indicator to how many projects they’ve completed and the dollar value of those projects.

Ok, so basically how I though it was calculated was something like: (Money * ReviewerRate) + (Rate * NumberRates), something like that, so a good reviewer will increase your points severally and if you have a large project with good budget, you will also increase your points.

Then I checked which was my position: #795, dissapointing, I had 9 reviews, but in average all my projects were low in budget, but then I check this:

ScriptLance Ranking

Sorry to put names, but is only as example. The user I’ve selected in the image had only one review and had much more points than me and than the other in the image also with 76 reviews; as I was curious about how many he had earn or which was the number of reviews the buyer had I checked his profile:

projects: 1
rate: 10
number of reviews of the buyer: 0 (well he had one of this programmer)
budget of the project: $35

This was astounding, how ScriptLance calculate their points to have much more than me (and other persons which more reviews and buyers with more reviews), personally I’ve worked with buyers which had more reviews and that doesn’t seem to be increased my points.

This seems to be a very bad algorithm in here, try to figure how to calculate the points, since it seems to be very random =)


Classic Music

I was discovering new classical songs these days, one I didn’t know it’s name and I heard the first time on a alcohol drink spot, the name was: O Mio Babbino Caro, Puccini


Another interpretation

Another song I like to hear is wide know but few interpretations are good enough to be heard: Ave Maria, Schubert here is one of these:

Another song I discovered was Gymnopedie No. 1, Satie, this due the movie: Janghwa, Hongryeon (A Tale of Two Sisters)

And a discovery was Keyboard Concerto No. 5 in F Minor, Bach, I think I’ve heard in some movie, but now I can’t remember which one; if you know, let me know.