How to read a portion of an image using RMagick?
I'm trying to load a large image and crop it into tiles really fast and with low memory consumption. An example is the way gdal2tiles s开发者_如何学Pythoncript http://www.maptiler.org/ does it, but gdal2tiles doesn't output the tiles the way I want them to be. Therefore I decided to develop my own version using ruby and RMagick(Imagemagick).(gdal2tiles barely uses any memory).
What I notice when using RMgick is that I need to load the whole image to memory first which kinda kills my system. Is there a way to read a portion of a image file manipulate it and then read the rest ?? Or maybe I should do it in some other way or use other libraries.
First thing to do is call descructive methods only. Don't call img.crop
but img.crop!
, that will save some memory.
But you might be interested in one of the alternatives. The problem with memory you describe, is almost unavoidable with RMagick. There are quite a lot of alternatives for RMagick for this very reason.
Because you need simple tasks only, I think the following libraries are usefull for you, because they are extremely optimised, but their featureset is limited.
- MiniMagick
- Chunky PNG
- Oily PNG
精彩评论