1 / 9

圖形處理

圖形處理. PHP 可讀取、產生 Gif 、 Jpg 、 Png 的 圖形,以及其他的圖形操作,不過必須注意以下幾點: 系統上必須安裝 GD Library (可用 phpinfo() 函數檢查) GD 1.5 (含)以下支援 Gif 、 Jpg , GD 1.6 以上支援 Png 、 Jpg 。 使用前先修改 php.ini 開啟 GD 模組功能 Win32 : extension=php_gd2.dll 將產生圖形的 PHP 寫成另一個網頁(因為輸出形態不同) 從要使用圖形的網頁超連結到產生圖形的網頁. 圖形處理-產生圖形. 產生圖形的網頁程序如下: <?

dalia
Download Presentation

圖形處理

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 圖形處理 • PHP可讀取、產生Gif、Jpg、Png的 圖形,以及其他的圖形操作,不過必須注意以下幾點: • 系統上必須安裝GD Library (可用phpinfo()函數檢查) • GD 1.5(含)以下支援Gif、Jpg,GD 1.6以上支援Png、Jpg。 • 使用前先修改php.ini開啟GD模組功能 • Win32:extension=php_gd2.dll • 將產生圖形的PHP寫成另一個網頁(因為輸出形態不同) • 從要使用圖形的網頁超連結到產生圖形的網頁

  2. 圖形處理-產生圖形 產生圖形的網頁程序如下: <? //image.php //定義輸出形態 Header("content-type: image/jpeg"); //定義圖形 $im=ImageCreate(100,100); //設定顏色 $black=ImageColorAllocate($im,0,0,0); $white=ImageColorAllocate($im,255,255,255); //其他敘述 ImageArc($im,50,50,98,70,0,360,$white); //製成JPG Imagejpeg($im); //釋放記憶體 ImageDestory($im); ?>

  3. 圖形處理-產生圖形 <?php /* Header( "Content-type: image/jpeg"); */ Header( "Content-type: image/gif"); /* create image */ $image = imagecreate(200,200); /* create color R=100, G=0, R=0 */ $maroon = ImageColorAllocate($image,100,0,0); /* create color R=255, G=255, R=255 */ $white = ImageColorAllocate($image,255,255,255); /* create color green */ $green = ImageColorAllocate($image,0,100,0); /* create white background*/ ImageFilledRectangle($image,0,0,200,200,$white); /* create frame*/ ImageRectangle($image,10,10,190,190,$maroon); /* create inner rectangle*/ ImageFilledRectangle($image,50,70,150,150,$maroon); /* display 5 fonts */ for ($i=1; $i <= 5; $i++) ImageString($image,$i,15,$i*10,'php.weblogs.com',$green); /* render image */ ImageJPEG($image); //ImageGIF($image); /*cleanup memory */ ImageDestroy($image); ?>

  4. 圖形處理-參數呼叫顯示 Chart.htm <img src="chart.php?color=00ff00&width=15&height=10"> Chart.php <? $corder=@$HTTP_GET_VARS['color']; $width=@$HTTP_GET_VARS['width']; $height=@$HTTP_GET_VARS['height']; if ($corder=='') {$corder='000000';} if ($width=='') {$width=20;} if ($height=='') {$height=20;} if ($width<=0) {$width=1;} if ($height<=0) {$height=1;} $im=imagecreate($width,$height); $back_color=$corder; $black=imagecolorallocate($im,hexdec(substr($back_color,0,2)),hexdec(substr($back_color,2,2)),hexdec(substr($back_color,4,2))); imagefill ($im,0,0,$black); imagepng($im); imagedestory($im); ?>

  5. 圖形處理-Resize圖形 gd_cut.php <? header("Content-type: image/jpeg"); $newWidth = 35; $newHeight = 35; $newImg = ImageCreate($newWidth,$newHeight); $origImg = ImageCreateFromjpeg("car1.jpg"); ImageCopyResized($newImg,$origImg,0,0,0,0,$newWidth,$newHeight,ImageSX($origImg),ImageSY($origImg)); Imagejpeg($newImg); ImageDestroy($newImg); ?>

  6. 圖形處理-Pie Chart

  7. 圖形處理-Pie Chart Index.php Piechart.php

  8. 圖形處理-條碼圖形 Barcode.php

  9. <?php function UPCAbarcode($code) { $lw = 2; $hi = 100; $Lencode = array('0001101','0011001','0010011','0111101','0100011', '0110001','0101111','0111011','0110111','0001011'); $Rencode = array('1110010','1100110','1101100','1000010','1011100', '1001110','1010000','1000100','1001000','1110100'); $ends = '101'; $center = '01010'; /* UPC-A Must be 11 digits, we compute the checksum. */ if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); } /* Compute the EAN-13 Checksum digit */ $ncode = '0'.$code; $even = 0; $odd = 0; for ($x=0;$x<12;$x++) { if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; } } $code.=(10 - (($odd * 3 + $even) % 10)) % 10; /* Create the bar encoding using a binary string */ $bars=$ends; $bars.=$Lencode[$code[0]]; for($x=1;$x<6;$x++) { $bars.=$Lencode[$code[$x]]; } $bars.=$center; for($x=6;$x<12;$x++) { $bars.=$Rencode[$code[$x]]; } $bars.=$ends; /* Generate the Barcode Image */ $img = ImageCreate($lw*95+30,$hi+30); $fg = ImageColorAllocate($img, 0, 0, 0); $bg = ImageColorAllocate($img, 255, 255, 255); ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg); $shift=10; for ($x=0;$x<strlen($bars);$x++) { if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; } if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; } ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color); } /* Add the Human Readable Label */ ImageString($img,4,5,$hi-5,$code[0],$fg); for ($x=0;$x<5;$x++) { ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg); ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg); } ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg); /* Output the Header and Content. */ header("Content-Type: image/png"); ImagePNG($img); } UPCAbarcode('12345678901'); ?> 圖形處理-條碼圖形

More Related