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.90 2010/11/26 17:22:01 mast 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:23:    doc[tag] += the_cache->documentation(tag +    " src='/internal-roxen-testimage'");    return doc;   }      #ifdef manual   constant tagdoc=(["cimg":#"<desc tag='tag'><p><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.</p> +  images. It is possible to pass attributes, such as the alt attribute, +  to the resulting tag by including them in the cimg tag. </p>   </desc>      <attr name='src' value='url' required='required'><p>    The path to the indata file.</p>      <ex><cimg src='/internal-roxen-testimage'/></ex>   </attr>      <attr name='filename' value='string'><p>   Append the filename value to the path. Recommended is not to append file suffix
Roxen.git/server/modules/graphics/cimg.pike:276:    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:332:    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:402:    "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)    // 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 )   {    if( !args->format )    args->format = "png";    if( !(args->src || args->data) )    RXML.parse_error("Required attribute 'src' or 'data' missing\n");
Roxen.git/server/modules/graphics/cimg.pike:466:    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:493:    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