Hey,
I don't have any advice on the bigger problem, but for
image manipulation,
PerlMagick isn't a bad choice. It provides a decent API to crop and
rotate, along with lots of other good stuff. I suspect
there's no particularly elegant solution to the second
part, and that you'll just need to do a lot of custom code.
Perhaps the other monks will prove me wrong :) I hope this
helps!