[PHP] 纯文本查看 复制代码 <?php
$file = "QQ20140507-1@2x.jpg";
// 返回数组,包含宽、高、类型
list($width, $height, $type) = getimagesize($file);
// 1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM。
$type_array = array(1=>"gif", 2=>"jpeg", 3=>"png");
header("Content-type: image/{$type_array[$type]}");
// 通过类型拼接相应的调用函数
$createimage = "imagecreatefrom".$type_array[$type];
// 创建图片资源
$image = $createimage($file);
// 颜色
$blue = imagecolorallocate($image, 0, 0, 255);
// 在图片中间画上字符串“Hello PHP”
$string = "Hello PHP";
$w = imagefontheight(5)*strlen($string);
$h = imagefontheight(5);
$x = ($width - $w) * 0.5;
$y = ($height - $h) * 0.5;
imagestring($image, 5, $x, $y, $string, $blue);
// 输出图片并释放资源
imagejpeg($image);
imagedestroy($image);
|