Home > Backend Development > PHP Tutorial > PHP code to add text to the pictures you post at any time_PHP tutorial

PHP code to add text to the pictures you post at any time_PHP tutorial

WBOY
Release: 2016-07-21 15:56:26
Original
838 people have browsed it

Header( "Content-type: image/jpeg");
function makethumb($srcFile,$text,$size=12,$R=0,$G=0,$B=0 ) {
if(!$text){
$text=''welcome to imbbs.cn'';
$size=20;
$R=255;
}
$data = GetImageSize($srcFile,&$info);

switch ($data[2]) {
case 1: //Image type, 1 is a GIF image
$im = @ImageCreateFromGIF($srcFile);
break;
case 2: //Image type, 2 is JPG image
$im = @imagecreatefromjpeg($srcFile);
break;
case 3 : //Image type, 3 is PNG image
$im = @ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH= ImageSY($im);

$ni= imagecreatetruecolor($srcW,$srcH);

imagecopyresampled($ni,$im,0,0,0,0,$srcW,$ srcH,$srcW,$srcH);
$font = "2.ttf";
$textcolor = imagecolorallocate($ni,$R,$G,$B); // Set text color
$i=0;
$txt='''';
$len=ceil((12*22)/$size);
$lgg=ceil(($size*16)/12 )-1;
while(strlen($txt)>0||!$i){
$start=$len*$i;
$kk=ceil($size*13/12 );
//$kk=13;
$txt=substr($text, $start, $len);
$hei=$i*$lgg+$kk;
imagettftext($ ni,$size, 0, 8, $hei, $textcolor, $font, $txt); // Write the text with a font
$i++;
}
ImageJpeg($ni);
}
if(!$size||$size<1)$size=12;
makethumb("face.jpg",$text,$size,$R,$G,$B);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318065.htmlTechArticle? Header("Content-type:image/jpeg"); functionmakethumb($srcFile,$text,$size =12,$R=0,$G=0,$B=0){ if(!$text){ $text=''welcometoimbbs.cn''; $size=20; $R=255; } $data =GetImageSize($srcF...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template