Howdy, folks. I'm using ImageMagick via rmagick to chop up large images
into tiles suitable for viewing using the zoomify flash viewer. It's all
working fine, except for the fact I'm producing images whose files are
5-6 times as large as those produced by the windows program.

The relevant snippets of code are:

  image = Magick::Image.read(filename).first
  levels = (Math.log([image.rows, image.columns].max.to_f / TILESIZE) /
Math.log(2)).ceil
  ...
  (0..levels).each do |level|
    n = levels - level
    # Obtain the image to tile for this level. The 0th level should
consist
    # of one tile, while the highest level should be the original image.
    level_image = image.resize(image.columns >> n, image.rows >> n)
    tiles(tmpdir, level, level_image) do |filename|
      ...
    end
    # Rmagick needs a bit of help freeing image memory.
    level_image = nil
    GC.start
  end

  # Splits the given image up into images of TILESIZE, writes them to
the
  # given directory, and yields their names
  def self.tiles(dir, level, image)
    slice(image.rows).each_with_index do |y_slice, j|
      slice(image.columns).each_with_index do |x_slice, i|
        # The images are named "level-column-row.jpg"
        filename = "#{level}-#{i}-#{j}.jpg"
        tile_image = image.crop(x_slice[0], y_slice[0], x_slice[1],
y_slice[1])
        tile_image.write("#{dir}/#{filename}") do
          # FIXME - the images end up being 4-5x larger than those
produced
          # by Zoomifier EZ and friends... no idea why just yet, except
to note
          # that the density of these tiles ends up being 400x400, while
          # everybody else produces tiles at 72x72. Can't see why that
would
          # matter though...
          self.quality = 90 
          self.colorspace = Magick::RGBColorspace
          self.compression = Magick::JPEGCompression
          self.density = '72x72'
        end
        # Rmagick needs a bit of help freeing image memory.
        tile_image = nil
        GC.start
        yield filename
      end
    end
  end

I'll note that the tile images produced by the windows program claim a
density of 72x72, while my images claim a density of 400x400.

Can anyone suggest what I may be doing incorrectly, or ways I might go
about diagnosing the problem? Many thanks.

- donald

_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to