ตัวอย่าง :
http://www.thaiall.com/php/testjpg.php
# some server do not support GD GIF but support GD JPEG.
# you can check by phpinfo();
header("Content-type: image/jpeg");
$imagesize = 80;
$myImage = ImageCreate($imagesize, $imagesize);
$white = ImageColorAllocate($myImage, 255, 255, 255);
$red = ImageColorAllocate($myImage, 255, 0, 0);
ImageFill($myImage, 0, 0, $red);
Imageinterlace($myImage, 1);
Imagearc($myImage, 40, 30, 20, 10, 0, 359, $white);
ImageLine($myImage, 5, 5, 70, 60, $white);
Imagestring($myImage, 3, 5, 40, ("This กขค."), $white);
Imagejpeg($myImage);
Imagedestroy($myImage);
######## securecode.php ###########
$FILE=file("topic.htm") ;
$key=count($FILE);
$key=ord(substr(crypt($key,$key),6,1)) * 100;
$key=$key + (ord(substr(crypt($key,$key),7,1)));
header("Content-type: image/jpeg");
$myImage = ImageCreate(80, 20);
$white = ImageColorAllocate($myImage, 255, 255, 255);
$red = ImageColorAllocate($myImage, 255, 0, 0);
ImageFill($myImage, 0, 0, $red);
Imagestring($myImage, 5, 5, 5, "$key", $white);
Imagejpeg($myImage);
Imagedestroy($myImage);
######## image.php ###########
// https://fonts.google.com/specimen/Kanit
$folder = '/home/public_html/quiz/';
class setfont {
function imagestring($im, $myfont, $x, $y, $s, $color){
$myfont = '/home/public_html/quiz/kanitregular.ttf';
imagettftext($im, 16, 0, $x, $y, $color, $myfont, $s);
}
}
header("Content-type: image/png");
$myImage = ImageCreate(1024,768);
$white = ImageColorAllocate($myImage, 255, 255, 255);
$blackblue = ImageColorAllocate($myImage, 0, 0, 64);
ImageFill($myImage, 0, 0, ImageColorAllocate($myImage, 0, 0, 255));
ImageFilledRectangle($myImage, 1, 1, 1022, 766, $blackblue);
$myfont = $folder . 'rsp_tlwgtypewriter.ttf';
$txt = "QUIZ";
$x_pos = (1024 / 2) - (strlen($txt) * 40 / 2);
Imagettftext($myImage, 40, 0, $x_pos , 80, $white, $myfont ,$txt);
$myfont = $folder . 'kanitregular.ttf'; // rsp_sawasdee.ttf
Imagettftext($myImage, 20, 0, 50, 150, $white, $myfont ,'ข้อใดไม่ใช่ภาษาโปรแกรม');
ImageLine($myImage, 20, 240, 1000, 240, $white);
ImageLine($myImage, 950, 20, 950, 700, $white);
$mygd = new setfont;
$mygd->imagestring($myImage, $myfont, 50, 300, "ก. ภาษาไพทอน", $white);
$myfont = $folder . 'kanitregular.ttf'; // rsp_thchakrapetch.ttf
Imagettftext($myImage, 16, 0, 50, 380, $white, $myfont ,'ข. ภาษาเอสคิวแอล');
Imagettftext($myImage, 16, 0, 50, 460, $white, $myfont ,'ค. ภาษาพีเอชพี');
Imagettftext($myImage, 16, 0, 50, 540, $white, $myfont ,'ง. ภาษาซี');
Imagettftext($myImage, 16, 0, 50, 620, $white, $myfont ,'จ. ภาษาจาวา');
Imagestring($myImage, 10, 700, 740, ("http://thainame.net/quiz/image.php"), $white);
Imagepng($myImage);
Imagedestroy($myImage);
// คำสั่งนี้ใช้ไทยไม่ได้ Imagestring($myImage, 16, 50, 300, ("This กขค."), $white);
http://www.thainame.net/quiz/image.php
http://www.thainame.net/quiz/image_bak.php