gdtest.pp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. { Author : Mike Bradbery
  2. Copyright: 2000 Mike Bradbery and others, see file "forum.txt" }
  3. program gdtest;
  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. Begin
  17. left := 60;
  18. top := 30;
  19. right := 580;
  20. bottom := 300;
  21. im:=gdImageCreate(600,390);
  22. black:=gdImageColorAllocate(im,0,0,0);
  23. white:=gdImageColorAllocate(im,255,255,255);
  24. red:=gdImageColorAllocate(im,255,0,0);
  25. green:=gdImageColorAllocate(im,0,255,0);
  26. blue:=gdImageColorAllocate(im,0,0,255);
  27. styleDotted[0] := red;
  28. styleDotted[1] := gdTransparent;
  29. styleDashed[0] := white;
  30. styleDashed[1] := white;
  31. styleDashed[2] := white;
  32. styleDashed[3] := gdTransparent;
  33. styleDashed[4] := gdTransparent;
  34. styleDashed[5] := gdTransparent;
  35. gdImageSetStyle(im,@styleDashed[0],6 );
  36. {box around the lot}
  37. gdImageRectangle(im,0,0,599,389,white);
  38. {main title}
  39. s1:='The Test Graph Title.';
  40. gdImageString(im, gdFontLarge,{im^.w}600 div 2 - ((length(s1)-1)*gdFontLarge^.w div 2),2{gdFontLarge^.h}, s1, white);
  41. 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);
  42. {box around the legend.}
  43. gdImageRectangle(im,100,350,500,370,white);
  44. s1:='The Legend.';
  45. gdImageString(im, gdFontLarge, 100+2, 350+2, s1, white);
  46. s1:='The Y axis Title.';
  47. gdImageStringUp(im, gdFontLarge, Left-5-gdFontLarge^.h-gdFontLarge^.w*2, top+(bottom-top) div 2+((length(s1)-1) * gdFontLarge^.w div 2),s1, white);
  48. // gdImageStringUp(im, gdFontLarge, 2, 50, @s1[1], white);
  49. s1:='The X axis Title.';
  50. gdImageString(im, gdFontLarge, left+(right-left) div 2-((length(s1)-1)*gdFontLarge^.w div 2),Bottom + 5 +gdFontLarge^.h,s1,white);
  51. {axis}
  52. gdImageLine(im,left,top,left,bottom,white);
  53. gdImageLine(im,left,bottom,right,bottom,white);
  54. { the origin is 30,360}
  55. for x:=0 to 10 do
  56. begin
  57. str(x,s1);
  58. gdImageLine(im,left+(x*(right-left) div 10) ,bottom,left+(x*(right-left) div 10) ,bottom+3,white);
  59. gdImageLine(im, left+(x*(right-left) div 10), bottom, left+(x*(right-left) div 10), top, gdStyled);
  60. gdImageString(im, gdFontLarge, left+(x*(right-left) div 10) - ((length(s1)-1)*gdFontLarge^.w div 2),bottom+5, s1, white);
  61. gdImageLine(im,left,bottom-(x*(bottom-top) div 10),left-3,bottom-(x*(bottom-top) div 10),white);
  62. gdImageLine(im, left, bottom-(x*(bottom-top) div 10), right, bottom-(x*(bottom-top) div 10), gdStyled);
  63. gdImageString(im, gdFontLarge,left-5-((length(s1)-1)*gdFontLarge^.w),bottom-(x*(bottom-top) div 10)-gdFontLarge^.h div 2, s1, white);
  64. end;
  65. f:=fopen(paramstr(1),'wb');
  66. if (f=nil) then
  67. writeln('Help, the file pointer is nil');
  68. gdImagePng(im,f);
  69. fclose(f);
  70. gdImageDestroy(im);
  71. End.