隨時給自己貼的圖片加文字的php代碼_PHP教程

來源:互聯網
上載者:User
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: //圖片類型,1是GIF圖
$im = @ImageCreateFromGIF($srcFile);
break;
case 2: //圖片類型,2是JPG圖
$im = @imagecreatefromjpeg($srcFile);
break;
case 3: //圖片類型,3是PNG圖
$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);

?>

http://www.bkjia.com/PHPjc/318065.htmlwww.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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.