顯示代碼有問題,圖片不顯示
<?php
$src = "001.png";
$info = getimagesize($src);
$type = image_type_to_extension($info[3], false);
$fun = "imagecreatefrom{$type}";
$image = $fun($src);
$font = "msyhl.ttc";
$content = "添加水印文字";
$color = imagecolorallocatealpha($image, 255, 255, 255, 50);
imagettftext($image, 20, 0, 20, 30, $color, $font, $content);
header("Content-type:" . $info['mime']);
$func = "image{$type}";
$func($image);
?>
2016-10-21
<?php
//獲取圖片
$src = "05.jpg";
//獲取圖片信息,圖片基本信息賦給變量
$info = getimagesize($src);
//通過圖像編號獲取圖像類型,格式,返回jpeg格式,false去點.
$type = image_type_to_extension($info[2],false);
//在內(nèi)存中創(chuàng)建一個一樣的類型圖像
$fun = "imagecreatefrom{$type}"; //$fun = imagecreatefromjpeg;
//把圖片復制到內(nèi)存中
$image = $fun($src);
//設置字體
$font= "msyh.ttf";
//水印
$content = "水印,盜版必究";
//$content = iconv("gbk","utf-8",$content);
//字體顏色RGB,透明度,50透明
$col = imagecolorallocatealpha($image,255,255,255,50);
//寫入文字,圖片源,大小,旋轉,x-偏移量,y-偏移量,顏色,,字體庫,內(nèi)容
imagettftext($image,20,20,200,300,$col,$font,$content);
//輸出圖片.告訴瀏覽器輸出圖片
header('content-type:'.$info['mime']);
$func = "image{$type}"; //變量格式名
$func($image);
//保存圖片
//imagejpeg($imahe,'newjpeg.jpe')
$func($image,'newimage',$type);
//銷毀圖片,操作完以后內(nèi)存殘留圖片副本
//圖片加工完成,清理內(nèi)存中圖片
imagedestroy($image);
?>