tiffcp.exe 将结果文件与循环中的结果文件合并
我正在构建一个 Web 应用程序,它需要多个 tiff 图像文件,并使用命令行中的 GNUWin32 tiffcp.exe 将它们合并为一个 tiff 图像文件。
我这样做的方法是循环遍历文件列表并构建一串文件名以合并到一个变量中。
strfileList = "c:文件夹\文件夹\文件夹\aased98-def-wsdeff-434fsdsd-dvv.tif c:文件夹\文件夹\文件夹\aased98-def-wsdeff-434fsdsd-axs.tif c:文件夹\文件夹\文件夹\aased98 -def-wsdeff-434fsdsd-dxzs.tif”
然后我只需写入命令行:
tiffcp.exe strFileList results.tif
文件名是 guid,因此路径相当长,我没有任何控制来缩短它们。因此,如果我有一堆这样的文档(超过 20 个文件左右),则字符串变量的长度超出了 Windows 命令行的限制,并且合并失败。
由于此过程只是合并文件,因此我的下一个想法是不要将文件名写入字符串,而只需一次合并一个文件。因此,循环第一次运行以下类型的代码:
tiffcp.exe file1.tif results.tif
结果是一个完美的 476k tif 文件。但循环的下一次迭代需要合并第二个文件以及第一个“结果”tif 文件的内容。所以我这样做:
tiffcp.exe results.tif file2.tiff results.tif
每次结果都是一个空白的1K tiff 文件?
我能找到的 tiffcp.exe 的所有示例都说 file1.tif file2.tif results.tif,没有一个使用结果文件写回到自身吗?
关于如何执行此操作有什么建议吗?
I am building a web app that takes several tiff image files and merges them together into one single tiff image file using GNUWin32 tiffcp.exe from command line.
The way I was doing it was to loop through the file list and build a string of file names to merge into one single variable.
strfileList = "c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dvv.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-axs.tif c:folder\folder\folder\aased98-def-wsdeff-434fsdsd-dxzs.tif"
Then I would just write to the command line:
tiffcp.exe strFileList results.tif
The file names are guids and so the paths are fairly long and I do not have any control to shorten them. So if I have a bunch of these documents (over 20 files or so), the length of the string variable exceeds the limits for windows command line and the merge fails.
Since this process is just merging files, my next thought was instead of writing the file names to a string, just do the merge one file at a time. So the first time the loop runs the following type of code:
tiffcp.exe file1.tif results.tif
The result is a perfect 476k tif file. But the next iteration of the loop needs to merge the second file plus the contents of the first "results" tif file. So I do this:
tiffcp.exe results.tif file2.tiff results.tif
The results each time are a blank 1K tiff file?
All the examples I can find of tiffcp.exe say file1.tif file2.tif results.tif, none use the results file to write back to itself?
Any suggestions on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将 -a 开关切换到 tiffcp.exe
我正在 Python 中执行类似的操作,并在文件处理循环中发出以下命令:
tiffcpp.exe -a temp.tif output.tif
工作正常。
Try the -a switch to tiffcp.exe
I'm doing something similar in Python and inside my file processing loop I'm issuing the command:
tiffcpp.exe -a temp.tif output.tif
works fine.
对于 ASP.NET 项目,您可能需要尝试 LibTiff.Net(免费、开源、BSD 许可证) 。 libtiff 库的该端口包含带有源代码的 tiffcp 实用程序。您可以尝试在您的代码中使用它。
免责声明:我是图书馆的维护者之一。
For an ASP.NET project you may want to try LibTiff.Net (free, open source, BSD license). That port of libtiff library contains tiffcp utility with source code. You may try to use it in your code.
Disclaimer: I am one of the maintainers of the library.
我相信您的问题是由于使用 results.tif 作为输入和输出引起的。如果您增加文件名(即 results1.tif 到 results2.tif 等),我相信它应该可以工作。
这是一种相当低效的方法(如果您有 10 个文件,则 tiff1 会被复制 9 次)。既然您引用了 libtiff,您可以查看 libtiff cp 的源代码并检查是否值得嵌入它。
I believe your problem is caused by the use of results.tif as both input as output. If you increment the file name (i.e. results1.tif to results2.tif etc.) I believe it should work.
This is a rather inefficient approach (tiff1 is copied 9 times if you have 10 files). Since you refer to libtiff, you may take a look at the source of libtiff cp and check if it is worthwhile to embed it.