f668602000-03-02Martin Nilsson // This is a roxen module. Copyright © 1999 - 2000, Roxen IS.
2e0a351999-12-09Martin Nilsson //
37bdda1999-05-18Per Hedbor #include <module.h> inherit "module"; inherit "roxenlib";
3b85e91999-11-15Per Hedbor constant thread_safe=1;
37bdda1999-05-18Per Hedbor  roxen.ImageCache the_cache;
76fd092000-04-06Mattias Wingstedt constant cvs_version="$Id: cimg.pike,v 1.14 2000/04/06 07:34:41 wing Exp $"; constant tagdesc="Provides the tag <tt>&lt;cimg&gt;</tt> that can be used " "to convert images between different image formats.";
37bdda1999-05-18Per Hedbor 
c043f82000-02-10Martin Nilsson constant module_type = MODULE_PARSER; constant module_name = "Image converter"; constant module_doc = tagdesc;
37bdda1999-05-18Per Hedbor 
2e0a351999-12-09Martin Nilsson TAGDOCUMENTATION
71a18b2000-02-02Jonas Wallden #ifdef manual
2e0a351999-12-09Martin Nilsson 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
37bdda1999-05-18Per Hedbor void start() { the_cache = roxen.ImageCache( "cimg", generate_image ); } mapping generate_image( mapping args, RequestID id ) {
34a9b81999-08-06Peter Bortas  if( args->data ) return roxen.low_decode_image( args->data ); else return roxen.low_load_image( args->src, id );
37bdda1999-05-18Per Hedbor } mapping find_internal( string f, RequestID id ) { return the_cache->http_file_answer( f, id ); }
34a9b81999-08-06Peter Bortas mapping get_my_args( mapping args, object id )
37bdda1999-05-18Per Hedbor {
36eceb2000-01-30Per Hedbor  mapping a= ([
34a9b81999-08-06Peter Bortas  "src":(args->src?fix_relative( args->src, id ):0),
37bdda1999-05-18Per Hedbor  "quant":args->quant,
c526921999-05-18Per Hedbor  "format":args->format, "maxwidth":args->maxwidth, "maxheight":args->maxheight, "scale":args->scale, "dither":args->dither,
b941aa1999-06-25Per Hedbor  "gamma":args->gamma,
34a9b81999-08-06Peter Bortas  "data":args->data,
37bdda1999-05-18Per Hedbor  ]);
c526921999-05-18Per Hedbor  foreach( glob( "*-*", indices(args)), string n ) a[n] = args[n];
34a9b81999-08-06Peter Bortas  return a; } string tag_cimg( string t, mapping args, RequestID id ) { mapping a = get_my_args( args, id );
37bdda1999-05-18Per Hedbor  args -= a;
54d2fa1999-11-24Per Hedbor  args->src = query_internal_location()+the_cache->store( a,id );
36eceb2000-01-30Per Hedbor  if( mapping size = the_cache->metadata( a, id, 1 ) )
37bdda1999-05-18Per Hedbor  { // image in cache (1 above prevents generation on-the-fly) args->width = size->xsize; args->height = size->ysize; } return make_tag( "img", args ); }
698c121999-05-19Peter Bortas  string tag_cimg_url( string t, mapping args, RequestID id ) {
54d2fa1999-11-24Per Hedbor  return query_internal_location()+the_cache->store(get_my_args(args,id),id);
698c121999-05-19Peter Bortas }