Question

I have a Rails app that uploads images for image processing, and I want to be able to 1) See how many pages/frames/scenes there are in an image, and 2) split multi-page images into single-page jpegs.

I'm having no trouble converting image types for single-scene images, but I can't quite puncture the ImageMagick documentation to understand exactly what I'm to do. The doc page I'm using is here:

http://www.imagemagick.org/www/escape.html

For the most part, I would like the code to be as simple as

def multiPage?( image )
  img = MiniMagick::Image.open(image.path)
  numPages = img.format("%n") #This returns Nil
  count > 1 ? true : false
end

Does anyone have a better idea of what to do than I do? Thanks in advance!

Was it helpful?

Solution

Ok, well this is a bit of a hack, but when I did:

numPages = img[:n]

I would get numPages resulting in a string of the letter 'n' as many times as there are pages in an image, so:

#img -> 4-page image
numPages = img[:n] # => 'nnnn'

Probably not the best answer, but at least it works.

UPDATE: Found a better way

numPages = Integer(img["%n"])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top