Roxen.git / server / modules / graphics / cimg.pike

version» Context lines:

Roxen.git/server/modules/graphics/cimg.pike:1:   // This is a roxen module. Copyright © 1999 - 2009, Roxen IS.   //      #include <module.h>   inherit "module";   constant thread_safe=1;      roxen.ImageCache the_cache;    - constant cvs_version = "$Id: cimg.pike,v 1.91 2012/05/09 13:52:12 jenny Exp $"; + constant cvs_version = "$Id$";   constant module_type = MODULE_TAG;   constant module_name = "Graphics: Image converter";   constant module_doc = "Provides the tag <tt>&lt;cimg&gt;</tt> that can be used "   "to convert images between different image formats.";         mapping tagdocumentation()   {    Stdio.File file=Stdio.File();    if(!file->open(__FILE__,"r")) return 0;
Roxen.git/server/modules/graphics/cimg.pike:237:      void create()   {    defvar("ext", Variable.Flag(0, VAR_MORE,    "Append format to generated images",    "Append the image format (.gif, .png, "    ".jpg, etc) to the generated images. "    "This is not necessary, but might seem "    "nicer, especially to people who try "    "to mirror your site.")); +  defvar ("default_args", +  Variable.Mapping (([]), 0, +  "Default Arguments", +  "Arguments to add implicitly to cimg/cimg-url/" +  "emit#cimg calls. Explicit arguments will take " +  "precedence over any arguments specified here."));   }      void start()   {    // Reuse previous cache object if possible    if (the_cache) {    // Update reference to callback function in case we've been reloaded    the_cache->set_draw_function(generate_image);    } else {    the_cache = roxen.ImageCache( "cimg", generate_image );
Roxen.git/server/modules/graphics/cimg.pike:277:    cache.flush_memory_cache();   }      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], Roxen.sizetostring(s[1]));   }    - void image_error (string fmt, mixed... args) - { -  if (RXML_CONTEXT) -  // generate_image can be called from within the cimg tag if -  // id->misc->generate_images is set. -  RXML.run_error (fmt, @args); -  else -  error (fmt, @args); - } -  +    array(Image.Layer)|mapping generate_image( mapping args, RequestID id )   {    array layers;       // Photoshop layers: don't let individual layers expand the image    // beyond the bounds of the overall image.    mapping opts = ([ "crop_to_bounds" : 1 ]);       if( args["process-all-layers"] )    opts->draw_all_layers = 1;
Roxen.git/server/modules/graphics/cimg.pike:309:    {    opts->scale_denom = (int)args["jpeg-shrink" ];    opts->scale_num = 1;    }       if( args->data )    layers = roxen.decode_layers( args->data, opts );    else    {    mixed tmp; - #if constant(Sitebuilder) + #if constant(Sitebuilder) && constant(Sitebuilder.sb_start_use_imagecache)    // Let SiteBuilder get a chance to decode its argument data    if (Sitebuilder.sb_start_use_imagecache) {    Sitebuilder.sb_start_use_imagecache(args, id);    tmp = roxen.load_layers(args->src, id, opts);    Sitebuilder.sb_end_use_imagecache(args, id);    } else   #endif    {    tmp = roxen.load_layers(args->src, id, opts);    }
Roxen.git/server/modules/graphics/cimg.pike:333:    return tmp;    else    layers = 0;    }    else layers = tmp;    }       if(!layers)    {    if( args->data ) -  image_error("Failed to decode specified data\n"); +  RXML.run_error("Failed to decode specified data\n");    else -  image_error("Failed to load specified image [%O]\n", args->src); +  RXML.run_error("Failed to load specified image [%O]\n", args->src);    }       if (!sizeof(filter(layers->image(), objectp))) -  image_error("Failed to decode layers in specified image [%O]\n", args->src); +  RXML.run_error("Failed to decode layers in specified image [%O]\n", +  args->src);    if(!args["exclude-invisible-layers"])    layers->set_misc_value( "visible",1 );    foreach( layers, Image.Layer lay )    if( !lay->get_misc_value( "name" ) )    lay->set_misc_value( "name", "Background" );       if( args["exclude-layers"] )    {    foreach( args["exclude-layers"] / ",", string match )    foreach( layers, Image.Layer lay )
Roxen.git/server/modules/graphics/cimg.pike:403:    "format":args->format,    "maxwidth":args->maxwidth,    "maxheight":args->maxheight,    "scale":args->scale,    "dither":args->dither,    "gamma":args->gamma,    "data":args->data,    ]);       if( args->src ) { -  // FIXME: Unacceptable error handling! -  mixed err = catch -  { +     a->src = Roxen.fix_relative( args->src, id );    array(int)|Stat st = (id->conf->try_stat_file(a->src, id));    if (st)    {    string fn = id->conf->real_file( a->src, id );    if( fn ) Roxen.add_cache_stat_callback( id, fn, st[ST_MTIME] );    a->mtime = (string) (a->stat = st[ST_MTIME]);    a->filesize = (string) st[ST_SIZE];    - #if constant(Sitebuilder) + #if constant(Sitebuilder) && constant(Sitebuilder.sb_start_use_imagecache)    // The file we called try_stat_file() on above may be a SiteBuilder    // file. If so we need to extend the argument data with e.g.    // current language fork.    if (Sitebuilder.sb_prepare_imagecache)    a = Sitebuilder.sb_prepare_imagecache(a, a->src, id);   #endif    } -  }; - #ifdef DEBUG -  if (err) -  report_error("<cimg> or <emit#cimg>: error in get_my_args(): %s\n", -  describe_backtrace(err)); - #endif +     }       a["background-color"] = id->misc->defines->bgcolor || "#eeeeee";    -  foreach( glob( "*-*", indices(args)), string n ) +  foreach( glob( "*-*", indices(args)), string n ) { +  if (!has_prefix(n, "data-"))    a[n] = args[n]; -  +  }       return a;   }      mapping check_args( mapping args )   { -  +  args = query ("default_args") + args;    if( !args->format )    args->format = "png";    if( !(args->src || args->data) )    RXML.parse_error("Required attribute 'src' or 'data' missing\n");    if (args->src == "")    RXML.parse_error("Attribute 'src' cannot be empty\n");    if( args->src && args->data )    RXML.parse_error("Only one of 'src' and 'data' may be specified\n");       return args;
Roxen.git/server/modules/graphics/cimg.pike:467:    constant plugin_name = "cimg";       array get_dataset( mapping args, RequestID id )    {    mapping res = ([ ]);    mapping a = get_my_args( check_args( args ), id );    string data;       int timeout = Roxen.timeout_dequantifier(args);    -  mixed err = catch // This code will fail if the image does not exist. -  { +     // Store misc->cacheable since the image cache can raise it and    // disable protocol cache.    int cacheable = id->misc->cacheable;    int no_proto_cache = id->misc->no_proto_cache;   #ifdef DEBUG_CACHEABLE    report_debug("%s:%d saved cacheable flags\n", __FILE__, __LINE__);   #endif    res->src=(query_absolute_internal_location(id)+    the_cache->store( a, id, timeout ));    if(args->filename && sizeof(args->filename))
Roxen.git/server/modules/graphics/cimg.pike:494:    res["file-size-kb"] = strlen(data)/1024;    if (lower_case(args->nodata || "no") == "no")    res["data"] = data;    res |= the_cache->metadata( a, id, 0, timeout ); // enforce generation   #ifdef DEBUG_CACHEABLE    report_debug("%s:%d restored cacheable flags\n", __FILE__, __LINE__);   #endif    id->misc->cacheable = cacheable;    id->misc->no_proto_cache = no_proto_cache;    return ({ res }); -  }; - #ifdef DEBUG -  report_error("<emit#cimg> error in get_dataset(): %s\n", -  describe_backtrace(err)); - #endif -  RXML.parse_error( "Illegal arguments or image: %s", -  describe_error (err)); +     }   }      class TagCImg   {    inherit RXML.Tag;    constant name = "cimg";    constant flags = RXML.FLAG_EMPTY_ELEMENT;       class Frame