問題描述
假設用戶上傳了一個 .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.
這篇關于為文本文件生成縮略圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!