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
  
// This is a roxen module. Copyright © 1999, Idonex AB. 
// 
 
#include <module.h> 
inherit "module"; 
inherit "roxenlib"; 
constant thread_safe=1; 
 
roxen.ImageCache the_cache; 
constant cvs_version="$Id: cimg.pike,v 1.12 2000/02/10 05:29:53 nilsson Exp $"; 
constant tagdesc="Provides the tag 'cimg' that can be used to convert images " 
  "between different image formats."; 
 
constant module_type = MODULE_PARSER; 
constant module_name = "Image converter"; 
constant module_doc  = tagdesc; 
 
TAGDOCUMENTATION 
#ifdef manual 
constant tagdoc=(["cimg":"<desc tag>"+tagdesc+"</desc>"]); 
/* 
      "Provides a tag 'cimg'. Usage: " 
      "&lt;cimg src=\"indata file\" format=outformat [quant=numcolors] [img args]&gt;", 
*/ 
#endif 
 
void start() 
{ 
  the_cache = roxen.ImageCache( "cimg", generate_image ); 
} 
 
mapping generate_image( mapping args, RequestID id ) 
{ 
  if( args->data ) 
    return roxen.low_decode_image( args->data ); 
  else 
    return roxen.low_load_image( args->src, id ); 
} 
 
mapping find_internal( string f, RequestID id ) 
{ 
  return the_cache->http_file_answer( f, id ); 
} 
 
mapping get_my_args( mapping args, object id ) 
{ 
  mapping a= 
  ([ 
    "src":(args->src?fix_relative( args->src, id ):0), 
    "quant":args->quant, 
    "format":args->format, 
    "maxwidth":args->maxwidth, 
    "maxheight":args->maxheight, 
    "scale":args->scale, 
    "dither":args->dither, 
    "gamma":args->gamma, 
    "data":args->data, 
  ]); 
  foreach( glob( "*-*", indices(args)), string n ) 
    a[n] = args[n]; 
  return a; 
} 
 
string tag_cimg( string t, mapping args, RequestID id ) 
{ 
  mapping a = get_my_args( args, id ); 
  args -= a; 
  args->src = query_internal_location()+the_cache->store( a,id ); 
  if( mapping size = the_cache->metadata( a, id, 1 ) ) 
  { 
    // image in cache (1 above prevents generation on-the-fly) 
    args->width = size->xsize; 
    args->height = size->ysize; 
  } 
  return make_tag( "img", args ); 
} 
 
string tag_cimg_url( string t, mapping args, RequestID id ) 
{ 
  return query_internal_location()+the_cache->store(get_my_args(args,id),id); 
}