生成文本文件的缩略图 [英] Generate thumbnail for text file

查看:84
本文介绍了生成文本文件的缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设用户上传了一个.txt或.php文件,而我想为其生成一个.png缩略图.有没有一种简单的方法,不需要我打开文件并将其内容写入新的.png?我有ImageMagick和FFmpeg可用,必须有一种方法可以利用它,但是我一直在寻找很多东西,但是还没有运气.

Suppose a user uploads a .txt or .php file, and I want to generate a .png thumbnail for it. Is there a simple way of doing it, that doesn't require me to open the file and write its contents into a new .png? I have ImageMagick and FFmpeg available, there must be a way to take advantage of that, but I've been looking a lot and no luck yet.

谢谢.

推荐答案

您可以使用ffmpeg:

 ffmpeg -video_size 640x480 -chars_per_frame 60000 -i in.txt -frames:v 1 out.png

但是,它有一些警告:

  • 默认情况下,每帧渲染6000个字符,因此它可能不会绘制所有文本.您可以使用-chars_per_frame和/或-framerate输入选项进行更改.默认帧频为25.

  • By default it renders 6000 characters per frame, so it may not draw all of your text. You can change this with the -chars_per_frame and/or -framerate input options. Default frame rate is 25.

文本不会自动自动换行,因此您必须为文本添加换行符以适合您的输出视频大小.

The text will not be automatically word wrapped so you will have to add line breaks for the text to fit your output video size.

这篇关于生成文本文件的缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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