生成DOC,TXT和RTF文件的预览图像 [英] Generating preview images for DOC, TXT and RTF files

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

问题描述

我一直试图找到一种方法来实现这一点,现在没有运气。

I've been trying to find a method of achieving this for awhile now with no luck.

不幸的是ImageMagicK不支持这些格式

Unfortunately none of these formats are supported by ImageMagicK

谢谢

推荐答案

自定义符合您要求的代码。

Customize the code to fit into your requirements.

我附上了一个文本文件生成的样本图片,其中包含生成TXT文件的预览图像句子,代码如下:

I've attached a sample image generated from a text file that contains "Generating preview images for TXT files" sentence by the following code:

<?php
Header ("Content-type: image/gif");
$txtfile = "test.txt";
$testarr = array();
if(!file_exists($txtfile)){
$string = "File not found.";
}
else{
$testarr = file($txtfile);
srand ((float) microtime() * 10000000);
$string = '-'.$testarr[array_rand($testarr)];
$string = substr($string,0,strlen($string)-2);
}
$font = 4;
$width = ImageFontWidth($font)* strlen($string);
$height = ImageFontHeight($font);
$im = ImageCreate($width,$height);
$x=imagesx($im)-$width ;
$y=imagesy($im)-$height;
$background_color = imagecolorallocate ($im, 242, 242, 242); //  white colored background
$text_color = imagecolorallocate ($im, 0, 0,0);  //  black colored text 
$trans_color = $background_color;           //  transparent 
imagecolortransparent($im, $trans_color);
imagestring ($im, $font, $x, $y, $string, $text_color);
imagegif($im);
ImageDestroy($im);
?>

链接很有用:

http://visionmasterdesigns.com/tutorial-convert-text-into-transparent-png -image-using-php /

http://www.phpro.org/examples/Text-to-Image-with-GD.html

这篇关于生成DOC,TXT和RTF文件的预览图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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