Drupal has a very powerful image manipulation UI, so why write code when we can easily use that for any purpose?! The problem is we can't! The reason is image manipulation UI only accepts one argument which is the source image. All other parameters and options are static.
Couple of days a ago i discovered a very amazing bug in Windows Vista, after searching for a fix on the internet i realized that many pople have the same problem. And not only it does not have any fix currently but also it's exists also on Windows 7 (And all Vista based operating systems like Windows Server 2008 etc).