利用php在圖片上寫字(中英文)

來源:互聯網
上載者:User
<?php/*param $image   圖象資源param size     字型大小param angle    字型輸出角度param showX    輸出位置x座標param showY    輸出位置y座標param font    字型檔位置param content 要在圖片裡顯示的內容*/class showChinaText {var $text = 'php網站程式開發';var $font = 'fonts/simsun.ttc'; //如果沒有要自己載入到相應的目錄下(本地www)var $angle = 0;var $size = 15;var $showX = 100;var $showY = 160;var $text0 = '2011 年 12 月 12 日';var $angle0 = 0;var $showX0 = 230;var $showY0 = 200;var $text1 = '新郎';var $angle1 = 20;var $showX1 = 135;var $showY1 = 285;var $text2 = '新娘';var $angle2 = 20;var $showX2 = 300;var $showY2 = 285;var $text3 = '北京市海澱區香格裡拉酒店';var $angle3 = 0;var $showX3 = 120;var $showY3 = 445;var $text4 = '上午十一點整';var $angle4 = 0;var $showX4 = 305;var $showY4 = 480;function showChinaText($showText = '') {$this->text = ! isset ( $showText ) ? $showText : $this->text;$this->show ();}function createText($instring) {$outstring = "";$max = strlen ( $instring );for($i = 0; $i < $max; $i ++) {$h = ord ( $instring [$i] );if ($h >= 160 && $i < $max - 1) {$outstring .= substr ( $instring, $i, 2 );$i ++;} else {$outstring .= $instring [$i];}}return $outstring;}function show() {//輸出頭內容Header ( "Content-type: image/png" );//建立圖象//$image = imagecreate(400,300);$image = imagecreatefromjpeg ( "01.jpg" ); //這裡的圖片,換成你的圖片路徑//定義顏色$red = ImageColorAllocate ( $image, 255, 0, 0 );$white = ImageColorAllocate ( $image, 255, 255, 255 );$black = ImageColorAllocate ( $image, 0, 0, 0 );//填充顏色//ImageFilledRectangle($image,0,0,200,200,$red);//顯示文字$txt = $this->createText ( $this->text );$txt0 = $this->createText ( $this->text0 );$txt1 = $this->createText ( $this->text1 );$txt2 = $this->createText ( $this->text2 );$txt3 = $this->createText ( $this->text3 );$txt4 = $this->createText ( $this->text4 );//寫入文字imagettftext ( $image, $this->size, $this->angle, $this->showX, $this->showY, $white, $this->font, $txt );imagettftext ( $image, $this->size, $this->angle0, $this->showX0, $this->showY0, $white, $this->font, $txt0 );imagettftext ( $image, $this->size, $this->angle1, $this->showX1, $this->showY1, $white, $this->font, $txt1 );imagettftext ( $image, $this->size, $this->angle2, $this->showX2, $this->showY2, $white, $this->font, $txt2 );imagettftext ( $image, $this->size, $this->angle3, $this->showX3, $this->showY3, $white, $this->font, $txt3 );imagettftext ( $image, $this->size, $this->angle4, $this->showX4, $this->showY4, $white, $this->font, $txt4 );//ImageString($image,5,50,10,$txt,$white);//顯示圖形imagejpeg ( $image );imagegif ( $image, "a2.jpg" );ImageDestroy ( $image );}}?><?php//使用$s = new showChinaText ();?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.