1. Apakah perpustakaan GD?
Pustaka GD ialah satu set fungsi perpustakaan untuk mencipta dan memproses pelbagai format imej Ia adalah salah satu perpustakaan pemprosesan imej yang paling biasa digunakan dalam PHP.
2. Pasang pustaka GD
Pasang pustaka GD di bawah CentOS/RedHat
1 Pasang pustaka sambungan GD PHP
2. Mulakan semula pelayan web
3. Semak versi perpustakaan GD yang disokong oleh PHP
Pasang pustaka GD di bawah Ubuntu/Debian
1. Pasang modul php5-gd
2. Mulakan semula pelayan web
3. Semak versi perpustakaan GD yang disokong oleh PHP
$image = imagecreate(200,200);
$. hitam = imagecolorallocate( $image,0,0,0);
imagefill($image,0,0,$black);
$white = imagecolorallocate ($imej, 255,255,255);
$text = 'Hello, GD!';
imagettftext($image,20,0,70,100,$white,'arial.ttf',$text);
imagepng($image,'test.png');
imagedestroy($image);
$src_image = imagecreatefrompng('test.png');
$src_width = imagesx($src_image);
$src_height = imagesy($src_image );
$new_width = $src_width * 0.5;
$new_height = $src_height * 0.5;
$new_image = imagecreatetruecolor($new_width,$new_height);
imageresampled_$src_image 0,0, 0,0,$new_width,$new_height,$src_width,$src_height);
imagepng($new_image,'test-resized.png');
$border_color = imagecolorallocate($new_image,128,128,128);
imagerectangle($new_image,0,0,$new_width-1,$new_height-1,$border_color);
imagepng($new_image,'test-bordered .png') ;
$cropped_image = imagecrop($new_image,['x'=>40,'y'=>40,'width'=>100 ,'height' =>100]);
imagepng($cropped_image,'test-cropped.png');
$blurred_image = imagefilter($new_image,IMG_FILTER_GAUSSIAN_BLUR );
imagepng($blurred_image,'test-blurred.png');
$pixel = imagecolorat. ($imej_baru,50 ,50);
$merah = ($piksel >> 16) & 0xFF;
$hijau = ($piksel >> 8) & 0xFF;
$biru = $pixel & 0xFF ;
$new_color = imagecolorallocate($new_image,255,0,0);
imagesetpixel($new_image,50,50,$new_color );
imagepng($new_image,'test-pixel.png');
$fill_color = imagecolorallocate($new_image,0,255,0);
imagefill( $new_image,0, 0,$fill_color);
imagepng($new_image,'test-filled.png');
$watermark_text = 'HAK CIPTA';
$font_size = 20;
$font_color = imagecolorallocate($new_image,0,0,0);
imagettftext($new_image ,$font_size,0,10,20,$font_color,'arial.ttf',$watermark_text);
imagepng($new_image,'test-watermark.png');
$imej watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark_image);
$watermark_height = imagesy($watermark_image);
$pos_x = ($new_width - $watermark_width) / 2;
$pos_y = ($new_height - $watermark_height) / 2;
imagecopy($new_image,$watermark_image,$pos_x,$pos_y,0,0,$watermark_width ,$watermark_height);
imagepng($new_image,'test-watermark.png');
$line_color = imagecolorallocate($new_image,0, 0,255);
imageline($new_image,0,0,$new_width,$new_height,$line_color);
imagepng($new_image,'test-line.png');
$rect_color = imagecolorallocate($new_image,0,255,0);
imagerectangle($new_image,20,20,$new_width-20,$new_height-20,$rect_color );
imagepng($ new_image,'test-rectangle.png');
$circle_color = imagecolorallocate($new_image,255,0,0);
$circle_center_x = $new_width/2 ;
$circle_center_y = $new_height/2;
$circle_diameter = $new_height * 0.8;
$circle_radius = $circle_diameter / 2;
new_lip. $circle_center_x,$circle_center_y,$circle_diameter ,$circle_diameter,$circle_color);
imagepng($new_image,'test-circle.png');
Atas ialah kandungan terperinci Panduan operasi perpustakaan GD dalam PHP. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!