将大图像分割成A4大小的图像
我想将一个大的 PNG 文件分割成 A4 页,以便可以轻松打印出来。
我想使用 Linux 命令行脚本来执行此操作:
shell> split-into-a4-sized-pages some-big.png
I would like to split a large PNG file into A4 pages so they can be printed out easily.
I would like to use a Linux command line script to do this:
shell> split-into-a4-sized-pages some-big.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我假设你有 ImageMagick &已安装 pdfposter。
A) 将 .png 转换为 .pdf(使用 ImageMagick)
B) 使用 pdfposter 平铺图像:
此命令将 input0 放大 4 倍,在默认 A4 上打印
media,并让 pdfposter 确定所需的页数。
I assume you have ImageMagick & pdfposter installed.
A) convert your .png to .pdf (using ImageMagick)
B) tile your image using pdfposter:
this command enlarges input0 exactly 4 times, print on the default A4
media, and let pdfposter determine the number of pages required.
尝试使用 imagemagick 的裁剪达到您想要的尺寸。
假设您有一个 640x962 图像:
并且您希望将其裁剪为 4 320x481 图像:
使用:
现在您必须找出一个图像中有多少像素打印机中的 A4 页面,以及图像的尺寸,这是一个非常简单的脚本。
照片,由 Pexels 的 Adonyi Gábor 拍摄。
Try using imagemagick's crop to your desired size.
Say you have a 640x962 image:
and you want to crop it into 4 320x481 images:
Use:
Now you'd have to find out how many pixels fit into an A4 page in your printer, and the dimensions of the image, and it is a very simple script from here.
Photo by Adonyi Gábor from Pexels.
您可以使用ImageMagick的convert来缩放图像;如果需要,ImageMagick 中可能还有其他工具可以剪辑图像。
You can use convert of ImageMagick to scale the image; there are probably other tools in ImageMagick to clip the image if you want.
我不知道有任何现成的命令行工具可以做到这一点。除非您一直使用它,否则 ImageMagick 可能需要比编写快速程序更长的时间来找出命令和选项的正确组合。
如果您了解 Python,一个简单的方法是使用 PIL(Python 成像库)编写几行程序。读取图像需要一行。在指定位置提取某些宽度和高度的块以保存为新的图像文件也很容易。添加几个 for 循环来扫描 A4 大小的块的行和列,就完成了。
如果您不了解 Python,几乎所有快速编写的编程语言都具有类似的功能。我想到了 GD 库;它有多种语言的绑定。
I don't know of any ready-made command line tool to do this. Unless you use it all the time, ImageMagick may take longer to figure out the right combination of commands and options, than to write a quickie program.
An easy way, if you know Python at all, is write a few-line program using PIL (Python Imaging Library). To read an image takes one line. To extract chunks of some width and height at specified location to save as new image files, is also easy. Add a couple for loops to scan rows and columns of A4-sized chunks, and you're done.
If you don't know Python, just about all quick-to-write programming languages have a similar capability. The GD library comes to mind; it has bindings for several languages.
NetPBM 的 pamdice 将拆分为多个页面。您必须根据所需 A4 图像的 DPI 设置 -width 和 -height 选项。
您还必须首先使用 pngtopam 将输入图像转换为 netpbm 格式:
这将留下一堆名为tile_x_y.ppm 的文件,
使用 pnmtopng 将每个文件转换为 PNG
NetPBM's pamdice will do the splitting into multiple pages. You'll have to set the -width and -height options according to the DPI of your desired A4 images.
And you'll also have to convert the input image to netpbm format first with pngtopam:
That will leave you will a bunch of files called tile_x_y.ppm
Convert each one of those to PNG with pnmtopng