5

我一直在寻找这个,但我没有找到我想要的,所以这是我的问题:

使用 PHP,我想创建一个非常大的图像文件,比如说 20000 千兆像素,然后我想在这个大图像上的特定位置添加一个小图像。我的电脑没有足够的内存来加载整个图像并以这种方式操作像素,所以我认为我需要访问硬盘上的图像数据并以某种方式操作它们,所以有人知道该怎么做吗?谢谢你的协助 :)

4

3 回答 3

2

ImageMagick 支持对非常大的文件进行操作。我在 PHP/ImageMagick API 中看不到支持,但您可以调用 (exec) 到命令行程序并使用它的磁盘缓存或流选项之一。

这里有一些处理大文件的文档:www.imagemagick.org

于 2013-03-05T12:12:58.173 回答
1

What would you do with an image that size? You couldn't serve it a browser, and even if you did manage to load it into the server, it would take up all the server resources, so you wouldn't be using the server for anything else in the meanwhile.

The short answer is that handling an image of that kind of scale as a single file in RAM is out of the question unless you've got an extremely powerful machine dedicated to it, and nothing else. At 20k x 20k pixels, even a simple monchrome image is going to take 400mb. Scale that up to any useful colour depth, and you're talking about gigabytes of RAM just to hold the graphic, and that's before we even start thinking about actually doing stuff with it.

I guess the solution is to look at what other people do, given the same problem.

Real applications that use images of that scale (eg mapping apps or panorama photos like this one) store their image as a series of much smaller blocks. Each block is a smaller image in its own right. They'd also usually have separate sets of blocks for each zoom level too. Handling a single massive image file is implausible for any realistic server environment, but smaller chunks make it easy to handle for both browser and server. The server just sends the blocks to the user that are in the current view; when the user scrolls or zooms, they get sent more blocks.

Your question mentions adding a smaller image to a specific location on the big one. Again, looking at how others do this, google maps and others handle this kind of thing using a layering system. The layers are built up and sent to the browser separately.

I know that doesn't directly answer the question, but I hope it gives you some options to think about.

于 2013-03-05T12:15:28.250 回答
0

只需保留一个简单的文件,而不是图像,并以任何自定义格式将像素数据存储在其中。PHP 有一个 fseek 函数,它允许您跳转到文件中的任何位置,因此您可以计算所需的位置并对其执行读/写。如果您有大小为 W x H 的图像,并且每个像素占用 3 个字节,则文件中像素 (X, Y) 的地址将为 (W * Y + X) * 3。

于 2013-03-05T14:19:14.390 回答