THANKS A LOT Weedpacket, your post really explained many things as of why and how I didn't get it to work for me. With your additional code I understood many things...
Now that I got going on this I must move one complaint, not to you but to the quality of the images... I was hoping that using this function would do what Photoshop does instead even if I work with PNG's it looks the resulting images have a corrupted palette of colors, it looks like if in Photoshop you are resizing a fixzed-palette GIF or converting a JPEG to a palette with not enough colors...
To make you understand I am attaching 4 pictures. They were resized from a hi quality digital camera JPEG picture of 1600x1200 where all the colors where nice. I converted the JPEG in PNG inside photoshop, keeping the same size, and the quality and colors were still great.
I tested both scripts (the one by Scott and the one by RZE) and the imags have the words 'scott' or 'rze' in their name to differentiate (I can see no difference between the results with the two codes).
These are the results (I am not posting the originals because one of them is over 2Mb and the other one 500k):
drum_medium_rze.png

drum_medium_scott.png

drum_small_rze.png

drum_small_scott.png

bass_medium_rze.png

bass_medium_scott.png

bass_small_rze.png

bass_small_scott.png

These are the results with JPEGs (not yet as good as Photoshop but definitely better than PNG):
drum_medium_rze.jpg

drum_small_rze.jpg

I had a little better luck with JPEG's, but the above result with the PNG's is quite depressing. Is this normal???
Anyway I ended up using RZE's code because in the notes I saw that he posted a newer code after Scott's that supposingly has a couple of improvements over Scott's code...