summaryrefslogtreecommitdiff
path: root/ipl/gprogs/webimage.icn
blob: 2b913fc80fc7e6e3381b48bc52c046f8b6f2cb58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
############################################################################
#
#	File:     webimage.icn
#
#	Subject:  Program to produce Web page for image files
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program takes the names of image files on the command line and
#  writes a Web page that embeds each image.
#
#  The following options are supported:
#
#	-a s	alignment, default "bottom"
#	-t s	title for page; default "untitled"
#	-n	include file names; default no names
#
############################################################################
#
#  Requires:  Version 9 graphics
#
############################################################################
#
#  Links:  options, wopen
#
############################################################################

link options
link wopen

record dim(w, h)

procedure main(args)
   local name, opts, title, dim, align, names

   opts := options(args, "t:a:n")
   title := \opts["t"] | "untitled"
   align := \opts["a"] | "bottom"
   names := opts["n"]

   write("<html><head><title>", title, "</title></head><body>")

   every name := !args do {
      dim := image_size(name) | {
         write(&errout, "*** cannot open image file ", image(name))
         next
         }
      write(
         if \names then name else "",
         "<p><img src=\"",
         name,
         "\" width=\"",
         dim.w,
         "\" height=\"",
         dim.h,
         "\" align=\"",
         align,
         "\"></p>"
         )
      }
   write("</body></html>")

end

procedure image_size(name)			#: size of GIF file
   local win, size

   win := WOpen("canvas=hidden", "image=" || name) | fail

   size := dim(WAttrib(win, "width"), WAttrib(win, "height"))

   WClose(win)

   return size

end