一、这种是直接显示在浏览器上,并不保存
function aaa(){
$user_id = 168955;
$bigImgPath = 'http://h-cdn.zealcdn.cn/20180706140903.png'; //原图,可以是本地力或者在线图片
$img = imagecreatefromstring(file_get_contents($bigImgPath));
$font = './Public/ziti/dkzt.ttc'; //一定要有对应的字体文件
$black = imagecolorallocate($img, 0,255,0); //字体颜色 RGB
$fontSize = 10; //字体大小
$circleSize = 0; //旋转角度
$left = 10; //左边距
$top = 20; //顶边距
=“要加的内容”; //要加的
imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $str);
list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
switch ($bgType) {
case 1: //gif
header('Content-Type:image/gif');
ob_clean();
imagegif($img);
break;
case 2: //jpg
header('Content-Type:image/jpg');
ob_clean();
imagejpeg($img);
break;
case 3: //jpg
header('Content-Type:image/png');
ob_clean();
imagepng($img);
break;
default:
break;
}
$insert['vip_id']=168955;
$insert['download_time']=$time;
$challenge_img = M("challenge_img")->add($insert);
imagedestroy($img);
}
二、这各在后边中路径和文件名的同保存到指定 的文件夹下
function img_id($img_url,$user_id){
$img = imagecreatefromstring(file_get_contents($img_url));
$font = 'public/dkzt.ttc';//字体文件
$black = imagecolorallocate($img,255, 255, 255);//字体颜色 RGB
$fontSize = 20; //字体大小
$circleSize = 0; //旋转角度
$left = 50; //左边距
$top = 210; //顶边距
imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, '要加的文字内容');
list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
switch ($bgType) {
case 1: //gif
header('Content-Type:image/gif');
ob_clean();
imagegif($img,'public/img/666.gif');
break;
case 2: //jpg
header('Content-Type:image/jpg');
ob_clean();
imagejpeg($img,'public/img/666.jpg');
break;
case 3: //jpg
ob_clean();
header('Content-Type:image/png');
imagepng($img,'public/img/666.png');
break;
default:
break;
}
imagedestroy($img);
}