As Lars suggested, RMagick is a good choice for this at RoR. If you are looking for PHP, I'm not sure that it can do some of the things you want, but GD2 (which is usually natively included in PHP if you installed PHP with a package manager) is a good tool. There is also a PHP extension for ImageMagick.
source share