不求甚解

此博客为个人学习之用,如与其他作品雷同,纯属巧合。

导航

Linux中如何将txt文件转为png格式

Posted on 2023-11-06 11:47  三年三班王小朋  阅读(138)  评论(0编辑  收藏  举报

Linux中如何将txt文件转为png格式

linux将txt文件转为png格式如果文本中没有中文,使用enscript,如果文本包含中文,使用paps命令。但是实际使用中,paps部分版本也不支持中文。。。

①ps转pdf格式

如果文本中没有中文,使用enscript

可以使用Linux下工具enscript,安装enscript需要配置yum仓库(everying的iso内包含)

yum install enscript -y

txt转ps

enscript -p test.ps -B test.txt
  • -p后面接输出的文件名
  • -B表示不将文件的页码、文件名等文件信息转到图片中

如果文本包含中文,使用paps

安装paps

yum install paps -y

txt转paps

paps test.txt > test.ps
  • --font=n  生成字体大小

② ps转pdf格式

使用Linux工具ps2pdf,安装ps2pdf

yum install ps2pdf -y

ps转pdf

ps2pdf test.ps test.pdf

③ pdf 转 png

使用ImageMagick中的convert命令,安装ImageMagick

yum install ImageMagick -y

使用convert进行转换

convert test.pdf test.png

一键生成磁盘使用情况的图片

df -hT| paps  > test.ps && ps2pdf test.ps test.pdf &&convert -background green -fill white -extent 600x300 test.pdf test.png
  • -background背景色,-fill前景色 
  • -extent设置画布的大小
  • -resize生成的图像保持宽高比(!不保留纵横比。例如: -resize 100x100!)
  • -density 200 图像每英寸面积内的像素点数,数值越高图片质量越高
  • -quality 100 这个为转换图片时的压缩率,0-100之间

将多个图片(test-0.png, test-1.png)合成一个图片(output.png)

convert -append test-0.png test-1.png  output.png
  • -append 竖着合成 +append 横着合成