如何使用 RMagick 读取图像的一部分?

发布于 2024-10-18 01:41:31 字数 357 浏览 9 评论 0原文

我正在尝试加载大图像并将其裁剪成图块,速度非常快且内存消耗低。一个例子是 gdal2tiles 脚本 http://www.maptiler.org/ 执行此操作的方式,但 gdal2tiles 没有这样做t 按照我想要的方式输出图块。因此我决定使用 ruby​​ 和 RMagick(Imagemagick) 开发自己的版本。(gdal2tiles 几乎不使用任何内存)。

我在使用 RMgick 时注意到,我需要首先将整个图像加载到内存中,这有点杀死我的系统。有没有办法读取图像文件的一部分并对其进行操作,然后读取其余部分?或者也许我应该以其他方式做到这一点或使用其他库。

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 script 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄人书 2024-10-25 01:41:31

首先要做的就是仅调用破坏性方法。不要调用 img.crop 而是调用 img.crop!,这会节省一些内存。

但您可能对其中一种替代方案感兴趣。您所描述的内存问题对于 RMagick 来说几乎是不可避免的。正是出于这个原因,RMagick 有很多替代品

因为您只需要简单的任务,所以我认为以下库对您有用,因为它们经过了极其优化,但它们的功能集有限。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文