/*
 * This Rexx/gd script creates all of the buttons for my web page
 */
Trace o
Call RxFuncAdd 'GdLoadFuncs', 'rexxgd', 'GdLoadFuncs'
Call GdLoadFuncs

text = 'Home Links Downloads Bug_Report Rexx/Tk Rexx/SQL Regina THE PDCurses Rexx/Wrapper Documentation Rexx/ISAM Rexx/gd Rexx/Trans Rexx/Curses'
/*
 * Find the maximum length of any of the button texts
 */
maxlen = 0
Do i = 1 To Words(text)
   if Length(Word(text,i)) > maxlen Then maxlen = Length(Word(text,i))
End
/*
 * Image size is based on size of largest text
 */
font = 'GDFONTMEDIUMBOLD'
x = ((1+GdFontGetWidth( font )) * maxlen) + 8
y = GdFontGetHeight( font ) + 8
Say 'Image size:' x 'x' y

Do i = 1 To Words(text)
   img = GdImageCreate( x, y )
   /*
    * First color allocated is the background - white
    */
   white = GdImageColorAllocate( img, 245, 255, 250 )
   background = GdImageColorAllocate( img, 0, 0, 102 )
   blue = GdImageColorAllocate( img, 0, 0, 255 )
   yellowgreen = GdImageColorAllocate( img, 73, 155, 0 )
   /*
    * Although most browsers can't handle transparent PNGs,
    * set the transparent index to the background anyway
   */
   call GdImageColorTransparent img, background
   /*
    * Determine text position - centered
    */
   xoff = (GdImageGetWidth( img ) % 2 ) - (((Length(Word(text,i)) * (GdFontGetWidth( font )))-1) % 2)
   /*
    * Draw our borders for the fill of the top left and right corners
    */
   call GdImageLine img, 6,   0, 0,   y-1, background
   call GdImageLine img, x-7, 0, x-1, y-1, background
   call GdImageFillToBorder img, 0,0, background, background
   call GdImageFillToBorder img, x-1,0, background, background
   /*
    * Write the string in blue, and save the image...
    */
   call GdImageString img, font, xoff, 3, Translate(Word(text,i),' ','_'), yellowgreen
   call GdImagePNG img, makename(Word(text,i),'green')
   /*
    * ..then overwrite the string in yellowgreen, and write this image.
    */
   call GdImageString img, font, xoff, 3, Translate(Word(text,i),' ','_'), blue
   call GdImagePNG img, makename(Word(text,i),'blue')

   call GdImageDestroy img
End

Return

makename: Procedure
Parse Arg text, color
text = Translate(text,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
text = Changestr( '/', text, '' )
text = Changestr( '_', text, '' )
Return color||text'.png'