ryanfb / iiif-dl

Command-line tile downloader/assembler for IIIF endpoints/manifests
MIT License
31 stars 2 forks source link

Argument list too long (Errno: : E2BIG) #9

Open Nimrod51 opened 5 years ago

Nimrod51 commented 5 years ago

Hi! I'm getting the tiles successfully downloaded using the script (running on Windows), but after getting the last tile there is the error that the Arg list too long -mode concatenate -tile 18x13, followed by a long list of all the tiles' paths, and finally the error (Errno: : E2BIG).

I've tried to use the -force tiling option, but got the same error (tiling is done correctly). I don't think the file is SO big that it should give the error, each tile is about 40kb and there's 234 tiles.

Any ideas or ways to overcome this error? Thanks!

Nimrod51 commented 5 years ago

EDIT I strongly suspect this has to do with then imagemagick or my shell limiting the number of arguments for the 'montage' function, but haven't found a workaround

ryanfb commented 5 years ago

It looks like the default shell length limits are much shorter on Windows (and I'm not sure what happens for tempfiles there either). I think that if I use e.g. Open3 for the command invocation instead, I'll avoid shell invocation (and hopefully therefore the argument length limit). Let me see if I can work something up real quick.

Nimrod51 commented 5 years ago

You're right, see here my question on stackoverflow. Do you suppose the problem would be resolved with Linux? I suspect that it's possible to resolve it using globbing as described in the imagemagick website, but I don't know Ruby well enough to get the syntax right

ryanfb commented 5 years ago

It may work in Linux, but I believe the latest version just pushed should fix it on all platforms even for images with a huge number of tiles (unless Windows still uses shell limits in popen calls). If you could test and let me know, I would greatly appreciate it!

Nimrod51 commented 5 years ago

Thanks for the prompt reply. However, it still returns the same error unfortunately: C:/Ruby25-x64/lib/ruby/2.5.0/open3.rb:199:in `spawn': Arg list too long - montage (Errno::E2BIG). The new code worked well with less tiles, so I assume it does have to do still with shell length limits. I will try testing it on linux and update again!

ryanfb commented 5 years ago

Thanks for reporting back. It seems like a better solution, then, might be to adapt the montage invocation so that it can fall back to some sort of piecewise method if it can't work due to shell length limits. Another option might be to try to use ImageMagick's globbing instead of shell globbing or passing every filename, but I'm not sure if that will work with Tempfile paths on all platforms.

Nimrod51 commented 5 years ago

Thanks for the tip! The code works on Linux with the large-tile image (234) great (unfortunately getting thin white horizontal lines in the image, but that's a separate issue I'll look into), so it's most likely a Windows issue.

ryanfb commented 5 years ago

Hmmm, interesting that you're getting lines in the composite image. I don't think IIIF has a spec for tile overlap like DZI does, which I have to handle here in my DZI downloader: https://github.com/ryanfb/dzi-dl/blob/master/dzi-dl.rb#L93-L114