Image::Magick can do what you need. I had to solve a problem where a spammer was sending an image chopped up into equal pieces, each piece attached to the email as an attachment. He used html and inline css to piece the fragments together to display the composite image in the email. I called him 'Mr. Puzzle'.
I was able to use Image::Magick to put the pieces back together, then another library to OCR the resulting image and run the text through a spam checker. Granted, the API for Image::Magick can be frustrating, but it is pretty fast. Keep at it, you'll get it.