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.