Looking For the Best Way to Rotate an Image: JavaScript, PHP, HTML etc

Hey All,
What I'm looking for is a way to rotate an image by non 90 degree angles (ie 90, 180, 270, 360). I am able to do it in PHP, but there are errors in the image, some pixels end up colored incorrectly and the image ends up resized and I lose transparency. I've done my share of searching on Google and now I'm looking for a real solution. The icon that I'm trying to rotate is being generated in PHP, so a means of transforming the coordinates used in creating the image would work as well. Just wondering if there is a more reliable way of rotating an image (its a simple icon on a transparent background) in JavaScript or PHP or Perl or whatever. Ideally, just need to be able to send a query string to a web page so I can dynamically create and rotate an image by n degrees.
Any help will be appreciated.

What did you try in PHP?

What kind of image is it? For best results when doing complicated things like rotation, it should be 24-bit color with alpha channel, not 8-bit color with a transparent color.