Branch: Tag:

2000-06-02

2000-06-02 01:29:42 by Martin Nilsson <mani@lysator.liu.se>

- Newstyled
- Added stat-dependency
- Added clear cache button
- Updated documentation

Rev: server/modules/graphics/cimg.pike:1.19

7:      roxen.ImageCache the_cache;    - constant cvs_version = "$Id: cimg.pike,v 1.18 2000/06/01 15:05:18 nilsson Exp $"; + constant cvs_version = "$Id: cimg.pike,v 1.19 2000/06/02 01:29:42 nilsson Exp $";   constant module_type = MODULE_PARSER;   constant module_name = "Image converter";   constant module_doc = "Provides the tag <tt>&lt;cimg&gt;</tt> that can be used "
27: Inside #if defined(manual)
     #ifdef manual   constant tagdoc=(["cimg":#" - <desc tag><short>Convert and manuipulate images between different image - formats.</short> The <tag>cimg</tag> makes it is possible to convert, alter size, and transform images between many formats.</desc> + <desc tag><short>Manipulates and converts images between different image + formats.</short> Provides the tag <tag>cimg</tag> that makes it is possible to convert, + resize, crop and in other ways transform images.</desc>      <attr name='src' value='uri' required>    The path to the indata file.
40: Inside #if defined(manual)
   Insert images from other sources, e.g. databases through entities or    variables.   <ex type='box'> - &lt;emit source='sql' query='select imagedata from images where id=37'&gt; - &lt;cimg data='&sql.imagedata;'/&gt; - &lt/emit&gt; + <emit source='sql' query='select imagedata from images where id=37'> + <cimg data='&sql.imagedata;'/> + </emit>   </ex>   </attr>",   
62: Inside #if defined(manual)
   Insert images from other sources, e.g. databases through entities or    variables.   <ex type='box'> - &lt;emit source='sql' query='select imagedata from images where id=37'&gt; - &lt;cimg data='&sql.imagedata;'/&gt; - &lt/emit&gt; + <emit source='sql' query='select imagedata from images where id=37'> + <cimg data='&sql.imagedata;'/> + </emit>   </ex>   </attr>",   ]);
76:    the_cache = roxen.ImageCache( "cimg", generate_image );   }    + mapping(string:function) query_action_buttons() { +  return ([ "Clear cache":the_cache->flush ]); + } +  + string status() { +  array s=the_cache->status(); +  return sprintf("<b>Images in cache:</b> %d images<br />\n<b>Cache size:</b> %s", +  s[0]/2, Roxen.sizetostring(s[1])); + } +    mapping generate_image( mapping args, RequestID id )   {    if( args->data )
89:    return the_cache->http_file_answer( f, id );   }    - mapping get_my_args( mapping args, object id ) + mapping get_my_args( mapping args, RequestID id )   {    mapping a=    ([ -  "src":(args->src?Roxen.fix_relative( args->src, id ):0), +  "src":Roxen.fix_relative( args->src, id ),    "quant":args->quant,    "crop":args->crop,    "format":args->format,
105:    "data":args->data,    ]);    +  a->stat = id->conf->stat_file( a->src,id ); +     a["background-color"] = id->misc->defines->bgcolor    || "#eeeeee";   
114:    return a;   }    - string tag_cimg( string t, mapping args, RequestID id ) - { + class TagCImg { +  inherit RXML.Tag; +  constant name = "cimg"; +  constant flags = RXML.FLAG_EMPTY_ELEMENT; +  mapping(string:RXML.Type) req_arg_types = ([ "src" : RXML.t_text ]); +  +  class Frame { +  inherit RXML.Frame; +  +  array do_return(RequestID id) {    mapping a = get_my_args( args, id );    args -= a;    args->src = query_internal_location()+the_cache->store( a,id );
125:    args->width = size->xsize;    args->height = size->ysize;    } -  return Roxen.make_tag( "img", args ); +  result = Roxen.make_tag( "img", args ); +  return 0;    } -  +  } + }    - string tag_cimg_url( string t, mapping args, RequestID id ) - { -  return query_internal_location()+the_cache->store(get_my_args(args,id),id); + class TagCImgURL { +  inherit RXML.Tag; +  constant name = "cimg-url"; +  constant flags = RXML.FLAG_EMPTY_ELEMENT; +  mapping(string:RXML.Type) req_arg_types = ([ "src" : RXML.t_text ]); +  +  class Frame { +  inherit RXML.Frame; +  +  array do_return(RequestID id) { +  result = query_internal_location()+the_cache->store(get_my_args(args,id),id); +  return 0;    } -  +  } + }