2
0

gdtestcgi.pp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. { Author : Mike Bradbery
  2. Copyright: 2000 Mike Bradbery and others, see file "forum.txt" }
  3. program gdtestcgi;
  4. uses libgd;
  5. var
  6. f:pFile;
  7. black,white:integer;
  8. red,green,blue:integer;
  9. im:gdImagePtr;
  10. s1,s2:string;
  11. points:array[0..2] of gdpoint;
  12. x : longint;
  13. styleDotted: array[0..1] of longint;
  14. styleDashed: array[0..5] of longint;
  15. top,bottom,left,right : longint;
  16. // Reference to the libc fdopen function, needed to open standard output.
  17. Function fdopen(FD: longint; Mode : Pchar) : Pointer;cdecl;external 'c';
  18. Begin
  19. left := 60;
  20. top := 30;
  21. right := 580;
  22. bottom := 300;
  23. im:=gdImageCreate(600,390);
  24. black:=gdImageColorAllocate(im,0,0,0);
  25. white:=gdImageColorAllocate(im,255,255,255);
  26. red:=gdImageColorAllocate(im,255,0,0);
  27. green:=gdImageColorAllocate(im,0,255,0);
  28. blue:=gdImageColorAllocate(im,0,0,255);
  29. styleDotted[0] := red;
  30. styleDotted[1] := gdTransparent;
  31. styleDashed[0] := white;
  32. styleDashed[1] := white;
  33. styleDashed[2] := white;
  34. styleDashed[3] := gdTransparent;
  35. styleDashed[4] := gdTransparent;
  36. styleDashed[5] := gdTransparent;
  37. gdImageSetStyle(im,@styleDashed[0],6 );
  38. {box around the lot}
  39. gdImageRectangle(im,0,0,599,389,white);
  40. {main title}
  41. s1:='The Test Graph Title.';
  42. gdImageString(im, gdFontLarge,{im^.w}600 div 2 - ((length(s1)-1)*gdFontLarge^.w div 2),2{gdFontLarge^.h}, s1, white);
  43. gdImageLine(im,600 div 2 - ((length(s1)-1)*gdFontLarge^.w div 2),gdFontLarge^.h+3,600 div 2 + ((length(s1)-1)*gdFontLarge^.w div 2),gdFontLarge^.h+3,white);
  44. {box around the legend.}
  45. gdImageRectangle(im,100,350,500,370,white);
  46. s1:='The Legend.';
  47. gdImageString(im, gdFontLarge, 100+2, 350+2, s1, white);
  48. s1:='The Y axis Title.';
  49. gdImageStringUp(im, gdFontLarge, Left-5-gdFontLarge^.h-gdFontLarge^.w*2, top+(bottom-top) div 2+((length(s1)-1) * gdFontLarge^.w div 2),s1, white);
  50. // gdImageStringUp(im, gdFontLarge, 2, 50, @s1[1], white);
  51. s1:='The X axis Title.';
  52. gdImageString(im, gdFontLarge, left+(right-left) div 2-((length(s1)-1)*gdFontLarge^.w div 2),Bottom + 5 +gdFontLarge^.h,s1,white);
  53. {axis}
  54. gdImageLine(im,left,top,left,bottom,white);
  55. gdImageLine(im,left,bottom,right,bottom,white);
  56. { the origin is 30,360}
  57. for x:=0 to 10 do
  58. begin
  59. str(x,s1);
  60. gdImageLine(im,left+(x*(right-left) div 10) ,bottom,left+(x*(right-left) div 10) ,bottom+3,white);
  61. gdImageLine(im, left+(x*(right-left) div 10), bottom, left+(x*(right-left) div 10), top, gdStyled);
  62. gdImageString(im, gdFontLarge, left+(x*(right-left) div 10) - ((length(s1)-1)*gdFontLarge^.w div 2),bottom+5, s1, white);
  63. gdImageLine(im,left,bottom-(x*(bottom-top) div 10),left-3,bottom-(x*(bottom-top) div 10),white);
  64. gdImageLine(im, left, bottom-(x*(bottom-top) div 10), right, bottom-(x*(bottom-top) div 10), gdStyled);
  65. gdImageString(im, gdFontLarge,left-5-((length(s1)-1)*gdFontLarge^.w),bottom-(x*(bottom-top) div 10)-gdFontLarge^.h div 2, s1, white);
  66. end;
  67. // open standard output as C file.
  68. f:=fdopen(1,'wb');
  69. // Write header
  70. Writeln('Content-type: image/png');
  71. Writeln;
  72. gdImagePng(im,f);
  73. fclose(f);
  74. gdImageDestroy(im);
  75. End.