home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / imahtmup.zip / imaghtml.cmd next >
OS/2 REXX Batch file  |  2002-01-28  |  10KB  |  371 lines

  1. /*  Feb,Mar,Oct 1999; Jan 2000 JTdidit jt@epix.net */
  2. lev='2.X.10'
  3. level = lev '30 Dec 2001'
  4. /* imaghtml.cmd - JT command to build html file to show all jpg and gif */
  5. /*  and PNG images in a directory.   */
  6.  
  7. /* --------------------------------------------------------------*/
  8. /* parameter block - edit carefully */
  9.  
  10. /* invocation to call netscape.
  11.    To automatically call netscape to view the output, change the
  12.    following line to netscape='Y' */
  13.  
  14. netscape='N'
  15.  
  16. /* and edit the next line with the correct path for your system. */
  17.  
  18. netscapecall="d:\ns461\program\netscape.exe -browser -l en_US"
  19.  
  20. /*lc - if lc=1 then file names are lowercased */
  21. lc=1
  22.  
  23. /* defalt for number of columns */
  24. defcols=5
  25.  
  26. /* file types (this param is an arg to a DIR command */
  27. ftypes="*.gif *.jpg *.png *.jpeg"
  28.  
  29. /* default output filename */
  30. outfile="images.htm"
  31.  
  32. /* max dimensions for an image; if either dimension exceeds
  33.    the limit, the image will be scaled by the browser when the
  34.    output file is viewed */
  35. maxwidth=150
  36. maxheight=150
  37.  
  38. /* window control for clickable thumbnails;
  39.   '_self'  - each thumbnail clicked will be opened in the same browser window
  40.         that you started out in.
  41.   '_blank'  - each thumbnail clicked will cause a separate window to opem
  42.   'Fullsize' - the first thumbnail clicked will cause a new window to open;
  43.             subsequent fullsize images will be shown in that window.
  44.   The advantage of using either of these over using a single window is that
  45.   the images.htm file doesn't need to reload each time you want to go
  46.   back to it from a thumbnail.  */
  47.  
  48. target='Fullsize'
  49.  
  50. /*  border control - width of border in pixels
  51.     0 = no border
  52.     default = 2   */
  53.  
  54. border=0
  55.  
  56. /* imgextra - optional extra attributes for the <img src="..." tag>  */
  57.  
  58. imgextra=''
  59.  
  60.  
  61. /* end of parameter block. You shouldn't edit anything below this */
  62. /* --------------------------------------------------------------*/
  63.  
  64. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  65. call SysLoadFuncs
  66.  
  67. Say 'imaghtml.cmd version' level
  68. say 'Usage is imaghtml [outfile [cols] [imagedir]]'
  69. Say 'Builds an HTML file to show all the jpg png & gif files in a directory'
  70. say 'Default directory for images is current directory'
  71. Say 'Default outfile is "images.htm"'
  72. Say 'Layout is in "cols" columns (default is 5)'
  73. Say 'This version shows the image size and file size for each file'
  74. Say 'and includes them in the URL along with an ALT=[filename] tag'
  75. Say 'useful for pasting from the html output file into the document'
  76. Say 'you are working on.'
  77. say 'If image dimensions exceed limits, a thumbnail is shown instead'
  78. say 'Clicking on the thumbnail will bring up the image itself'
  79. say ''
  80.  
  81. here=directory()
  82. if right(here,1)='\' then here=left(here,length(here)-1)
  83. parse arg arg1 arg2 where
  84. if arg1 \= '' then outfile=arg1
  85.      cols=defcols
  86. if where='' & datatype(arg2)='CHAR' then do
  87.      where=arg2
  88.      end
  89. if datatype(arg2)='NUM'  then cols=arg2
  90.  
  91. if where='' then do
  92.     fullpath=0
  93.     where=here
  94.     end
  95.   else do
  96.     fullpath=1
  97.     if pos('\',where)=0 then where=here||'\'||where
  98.     end
  99. if pos('\',outfile)=0 & pos(':',outfile)=0 then outfile=here||'\'||outfile
  100.     else fullpath=1
  101.  
  102. do while queued()>0
  103.    pull junk
  104.    end
  105.  
  106. if where \= here then xxx=directory(where)
  107.  '@dir /B' ftypes '2> NUL | sort | RXQUEUE'
  108. if where \= here then xxx=directory(here)
  109.  
  110. if substr(where,length(where))='\' then where=left(where,length(where)-1)
  111.  
  112. if queued()=0 then do
  113.    say 'No files to process'
  114.    exit
  115.    end
  116.  
  117.  
  118. j=1
  119. do while queued()>0
  120.     parse pull files.j
  121.     if lc=1 then do
  122.        files.j=translate(files.j,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  123.        end
  124.     j=j+1
  125.     end
  126. files.0=j-1
  127.  
  128. xx = stream(outfile,C,'query exists')
  129.     if xx<>'' then do
  130.     say 'Output file' outfile 'exists'
  131.     say 'Press Enter to replace it; X to quit'
  132.     yy=linein()
  133.     if yy<>'' then exit
  134.     xx=sysfiledelete(outfile)
  135.     end
  136.  
  137. xx=stream(outfile,C,'open write')
  138.  
  139. header.0=9
  140. header.1='<HTML>'
  141. header.2='<HEAD>'
  142. header.3='<TITLE>Images in' where '</TITLE><BR>'
  143. header.4='<BASE TARGET='||target||'>'
  144. header.5='</HEAD><BODY>'
  145. header.6='<P><BIG><B>IMAGHTML.CMD' lev '(by Julian Thomas) did this</BIG>'
  146. header.7='</B>on' date()||'.'
  147. header.8='<P><FONT SIZE="-2">Size is width * height</FONT><P>'
  148. header.9="<TABLE BORDER='2' RULES='ALL'><TR>"
  149. /* header.9="<TABLE BORDER='2' RULES='NONE'><TR>" */
  150.  
  151.  
  152. do i=1 to header.0
  153.    xx= lineout(outfile, header.i)
  154.    end
  155.  
  156. call putqueue
  157. call lineout outfile, '</HTML>'
  158. call lineout outfile
  159. if translate(left(netscape,1))\='Y' then exit
  160. say 'calling Netscape'
  161. netscapecall outfile
  162. exit
  163.  
  164. putqueue: procedure expose outfile cols maxwidth maxheight files. where fullpath border imgextra
  165.  
  166. i=0
  167. do j=1 to files.0 by 1
  168.    filenam = files.j
  169.    if fullpath = 0 then do
  170.       fullname=filenam
  171.       linkname=filenam
  172.       end
  173.    else do
  174.        fullname=where||'\'||filenam
  175.        linkname=fullname
  176.        do while pos('\',linkname)>0
  177.           zz=pos('\',linkname)
  178.           linkname=left(linkname,zz-1)||'/'||substr(linkname,zz+1)
  179.       end /* change \ to / loop */
  180.        if substr(linkname,2,1)=':' then
  181.               linkname='file:///'||left(linkname,1)||'|'||substr(linkname,3)
  182.        end  /* rebuild linkname */
  183.    qdot=lastpos('.',filenam)
  184.    ext=translate(substr(filenam,qdot+1))
  185.    filesize=stream(fullname,'C','QUERY SIZE')
  186.    siz=''
  187.    if ext='GIF' then do
  188.         call gifsize
  189.         end /* GIF file */
  190.     else if ext='JPG' | ext= 'JPEG' then do
  191.        call jpgsize
  192.        end
  193.     else if ext='PNG' then do
  194.        call pngsize
  195.        end
  196.     else do
  197.        say 'skipping unsupported file type' fullname
  198.        iterate
  199.        end
  200.  
  201.        if width>0 then siz=width||'x'||height
  202.           else do
  203.           say 'bad size values for file' fullname ';skipping file'
  204.           iterate
  205.           end
  206.  
  207. /* see if we use it as is or need to scale it */
  208.  
  209. if width<=maxwidth & height<=maxheight then do /*   it's ok as is */
  210.    ws=width
  211.    hs=height
  212.    scale=1
  213.    call lineout outfile, ''
  214.    call lineout outfile, '<TD>'
  215.    outlin='<IMG SRC="'
  216.    outlin=outlin||linkname||'"'
  217.    outlin=outlin||' ALT="'||filenam||'" WIDTH='||ws
  218.    outlin=outlin 'HEIGHT='||hs||' BORDER='||border
  219.    if imgextra<>'' then outlin=outlin imgextra
  220.    outlin=outlin||'>'
  221.    call lineout outfile, outlin
  222.    outlin='<BR>' filenam '<BR>' siz '<BR>' filesize 'bytes'
  223.    outlin=outlin||'</TD>'
  224.    call lineout outfile, outlin
  225.    end
  226.  
  227.  
  228.    else do    /* we need to scale the image */
  229.    wx=maxwidth/width
  230.    hx=maxheight/height
  231.    scale=min(wx,hx)
  232.    ws=format(width*scale,,0)
  233.    hs=format(height*scale,,0)
  234.    call lineout outfile, ''
  235.    call lineout outfile, '<TD>'
  236.    outlin='<A HREF="'||linkname||'"><IMG SRC="'
  237.    outlin=outlin||linkname||'"'
  238.    outlin=outlin||' ALT="'||filenam||'" WIDTH='||ws
  239.    outlin=outlin 'HEIGHT='||hs
  240.    outlin=outlin 'BORDER=0'
  241.    outlin=outlin||'></A>'
  242.    call lineout outfile, outlin
  243.    outlin='<BR>' filenam '<BR>' siz '<BR>' filesize 'bytes'
  244.    outlin=outlin||'<BR>'
  245.    call lineout outfile, outlin
  246.    outlin="  scale factor " format(scale,1,3) '</TD>'
  247.    call lineout outfile, outlin
  248.    outlin="<!--  THIS is what to use for the full size image"
  249.    call lineout outfile, outlin
  250.    outlin='<IMG SRC="'
  251.    outlin=outlin||filenam||'"'
  252.    outlin=outlin||' ALT="'||filenam||'" WIDTH='||width
  253.    outlin=outlin 'HEIGHT='||height||' BORDER='||border
  254.    if imgextra<>'' then outlin=outlin imgextra
  255.    outlin=outlin||'>'
  256.    call lineout outfile, outlin
  257.    outlin=" end comment for true image  -->"
  258.    call lineout outfile, outlin
  259.    end
  260.  
  261.    i=i+1
  262.    if i=cols then do
  263.       call lineout outfile,'<TR>'
  264.       i=0
  265.       end  /* new table row */
  266.    end  /* files loop */
  267.  
  268. call lineout outfile,'</TABLE>'
  269. return
  270.  
  271. jpgsize: procedure expose fullname width height
  272. /* JPGINFO.CMD */
  273. /* JTdidit program to try to extract size of a JPG file */
  274.  
  275.  
  276. width=''
  277. height=''
  278.  
  279. xx=stream(fullname,'C','open read')
  280.    if xx <> 'READY:' then do
  281.       say "Can't open file" fullname
  282.       return
  283.       end
  284.  
  285. head=charin(fullname,,2)
  286. if head<>'FFD8'X then do
  287.    say fullname 'Not a JPG file'
  288.    return
  289.    end
  290.  
  291. do while chars(fullname)>0
  292.    xx=charin(fullname,,2)
  293.    if (xx>= "FFC0"X) & (xx<="FFC3"X) then do
  294.       /* we have what we hope is the data frame */
  295.       junk=charin(fullname,,3) /* pass over length and precision */
  296.       hhex=charin(fullname,,2)
  297.       whex=charin(fullname,,2)
  298.       height= c2d(hhex)
  299.       width= c2d(whex)
  300.       call stream fullname,'C','CLOSE'
  301.  
  302.       return
  303.       end
  304.    else do
  305.       xy=charin(fullname,,2)  /* get length */
  306.       length=c2d(xy)
  307.       junk=charin(fullname,,length-2)  /* skip over it */
  308.       end
  309.   end
  310.   say 'No image segment found in file' fullname
  311.   return
  312.  
  313.  
  314. gifsize: procedure expose fullname width height
  315. /* GIFINFO.CMD */
  316. /* JTdidit program to try to extract size of a GIF file */
  317.  
  318. head=charin(fullname,,3)
  319. if head<>'GIF' then do
  320.    say fullname 'Not a GIF file'
  321.    exit
  322.    end
  323.  
  324. junk=charin(fullname,,3)  /* pass over 87a or 89a or whatever */
  325.  
  326.    x=charin(fullname,,1)
  327.    y=charin(fullname,,1)
  328.    width=c2d(y||x)
  329.  
  330.    x=charin(fullname,,1)
  331.    y=charin(fullname,,1)
  332.    height=c2d(y||x)
  333.  
  334. /*  say 'W' width 'H' height */
  335.  
  336. call stream fullname,'C','CLOSE'
  337. return
  338.  
  339.  
  340. pngsize: procedure expose fullname width height
  341.  
  342. width=''
  343. height=''
  344.  
  345. xx=stream(fullname,'C','open read')
  346.    if xx <> 'READY:' then do
  347.       say "Can't open file" fullname
  348.       return
  349.       end
  350.  
  351. head=charin(fullname,,8)
  352. if head<>'89504e470d0a1a0a'X then do
  353.    say fullname 'Not a PNG file'
  354.    return
  355.    end
  356.  
  357.  
  358.       junk=charin(fullname,,4)
  359.       ihdr=charin(fullname,,4)
  360.       if ihdr<>'IHDR' then do
  361.          say 'illegal format PNG file' fullname
  362.      return
  363.      end
  364.       whex=charin(fullname,,4)
  365.       hhex=charin(fullname,,4)
  366.       height= c2d(hhex)
  367.       width= c2d(whex)
  368.       call stream fullname,'C','CLOSE'
  369.  
  370.       return
  371.