ImageMagick的作物巨大的形象 [英] ImageMagick crop huge image

查看:123
本文介绍了ImageMagick的作物巨大的形象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个巨大的形象创造的瓷砖说40000x40000

我发现了线的ImageMagick他裁剪瓷砖的脚本。它工作正常,小的图像,例如说10000x5000

一旦我得到它最终要使用多少内存更大的任何和计算机死亡。

我已经加入了极限的选择,但他们不似乎生效

我有监视器在那里,但它并不能帮助作为脚本只是减慢和locksup机

这似乎只是戈布尔像交换磁盘的50gig然后杀死机

我认为这个问题是因为它作物每个瓦片这让他们在内存中。我想我需要的是为它写每瓦到磁盘,因为它创造它没有将其全部保存在内存中了。

下面是脚本迄今

 #!/斌/庆典
 文件= $ 1
 功能瓦(){
 转换-monitor -limit内存2GiB -limit映射2GiB -limit区2GB $文件进制$ {S}%×256×256 -crop \\
 -set文件名:瓷砖%[FX:page.x / 256] _%[FX:page.y / 256]\\
 + repage +毗$ {文件%。*} _ $ {S} _%[文件名:瓷砖]巴纽
 }
 S = 100
 瓦
 S = 50
 瓦


解决方案

有更多的挖掘,并从球员一些帮助上的 ImageMagick的论坛我设法得到它的工作。

的窍门能让它的工作是 .mpc 格式即可。由于这是所使用的ImageMagick它不需要在初始图像转换的本机图像格式,它只是切出它需要的片。这是第二个脚本我安装的情况。

假设你有一个叫 50000x50000 的.tif 图片 myLargeImg.tif 。首先使用下面的命令将其转换为原生的图像格式:

 转换-monitor -limit区2MB myLargeImg.tif myLargeImg.mpc

然后,运行波纹管bash脚本,将创建切片。创建一个在同一文件夹中MPC图像名为 tiler.sh 文件,并把下面的脚本:

 #!/斌/庆典
 SRC = $ 1
 宽度=`识别-format%W $ src`
 极限= $ [$宽度/ 256]
 回声计数= $限制* ​​$限额=$((*上限限制))砖
 极限= $((限-1))
 在'序列0 X $ limit`;做
   在`序列0是$ limit`;做
     瓦= tile- $ X- $ y.png
     回声-n $瓷砖
     W = $((X * 256))
     H = $((Y * 256))
     转换-debug缓存-monitor $ SRC -crop 256×256 + $ W + $ H $瓷砖
   DONE
 DONE

在您的控制台/终端中运行以下命令并观察出现瓷砖逐一在时间到你的文件夹中。

 上海./tiler.sh myLargeImg.mpc

I am trying to create tiles from a huge image say 40000x40000

i found a script on line for imagemagick he crops the tiles. it works fine on small images like say 10000x5000

once i get any bigger it ends up using to much memory and the computer dies.

I have added the limit options but they dont seem to take affect

i have the monitor in there but it does not help as the script just slows down and locksup the machine

it seems to just goble up like 50gig of swap disk then kill the machine

i think the problem is that as it crops each tile it keeps them in memory. What i think i needs is for it to write each tile to disk as it creates it not store them all up in memory.

here is the script so far

 #!/bin/bash
 file=$1
 function tile() {
 convert -monitor -limit memory 2GiB -limit map 2GiB -limit area 2GB $file -scale ${s}%x -crop 256x256 \
 -set filename:tile "%[fx:page.x/256]_%[fx:page.y/256]" \
 +repage +adjoin "${file%.*}_${s}_%[filename:tile].png"
 }
 s=100
 tile
 s=50
 tile

解决方案

After a lot more digging and some help from the guys on the ImageMagick forum I managed to get it working.

The trick to getting it working is the .mpc format. Since this is the native image format used by ImageMagick it does not need to convert the initial image, it just cuts out the piece that it needs. This is the case with the second script I setup.

Lets say you have a 50000x50000 .tif image called myLargeImg.tif. First convert it to the native image format using the following command:

 convert -monitor -limit area 2mb myLargeImg.tif myLargeImg.mpc

Then, run the bellow bash script that will create the tiles. Create a file named tiler.sh in the same folder as the mpc image and put the below script:

 #!/bin/bash
 src=$1
 width=`identify -format %w $src`
 limit=$[$width / 256]
 echo "count = $limit * $limit = "$((limit * limit))" tiles"
 limit=$((limit-1))
 for x in `seq 0 $limit`; do
   for y in `seq 0 $limit`; do
     tile=tile-$x-$y.png
     echo -n $tile
     w=$((x * 256))
     h=$((y * 256))
     convert -debug cache -monitor $src -crop 256x256+$w+$h $tile
   done
 done

In your console/terminal run the below command and watch the tiles appear one at at time into your folder.

 sh ./tiler.sh myLargeImg.mpc

这篇关于ImageMagick的作物巨大的形象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆