6

In linux i'm doing the below to convert a multipage PDF into images resized and with a high resolution:

convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 test.pdf test.jpg

For the life of me, i can't seem to reproduce this EXACT command using RMagick. I tried something like this below but the image doesn't have the size/resolution i want. Any ideas?

Magick::ImageList.new('test.pdf').each_with_index { |img, i|
  img.resize_to_fit!(800, 800)
  img.write("test-#{i}.jpg") {
    self.quality = 80
    self.density = '300'
    self.colorspace = Magick::RGBColorspace
    self.interlace = Magick::NoInterlace
  }
}

Cheers, G.

gurpal2000
  • 1,004
  • 1
  • 17
  • 35
  • 3
    FOUND the solution. You have to use: img = Magick::Image::read('test.pdf') { self.density = 300 }.each { |img| # blah } This basically reads in the file with the specified density. – gurpal2000 Sep 02 '10 at 22:26

1 Answers1

6

Use block with quality options for method new instead of method write:

Magick::ImageList.new('test.pdf') do
  self.quality = 80
  self.density = '300'
  self.colorspace = Magick::RGBColorspace
  self.interlace = Magick::NoInterlace
end.each_with_index do |img, i|
  img.resize_to_fit!(800, 800)
  img.write("test-#{i}.jpg")
end

Not sure actually about colorspace and interlace options, but it definitely works for quality and density.

Oleksandr Avoiants
  • 1,889
  • 17
  • 24