f66860 | 2000-03-02 | Martin Nilsson | |
|
2e0a35 | 1999-12-09 | Martin Nilsson | |
|
37bdda | 1999-05-18 | Per Hedbor | | #include <module.h>
inherit "module";
|
3b85e9 | 1999-11-15 | Per Hedbor | | constant thread_safe=1;
|
37bdda | 1999-05-18 | Per Hedbor | |
roxen.ImageCache the_cache;
|
0023a6 | 2000-08-22 | Martin Nilsson | | constant cvs_version = "$Id: cimg.pike,v 1.25 2000/08/22 19:00:25 nilsson Exp $";
|
c043f8 | 2000-02-10 | Martin Nilsson | | constant module_type = MODULE_PARSER;
constant module_name = "Image converter";
|
739058 | 2000-06-01 | Martin Nilsson | | constant module_doc = "Provides the tag <tt><cimg></tt> that can be used "
"to convert images between different image formats.";
|
2fafd2 | 2000-05-18 | Kenneth Johansson | |
|
739058 | 2000-06-01 | Martin Nilsson | | mapping tagdocumentation() {
Stdio.File file=Stdio.File();
if(!file->open(__FILE__,"r")) return 0;
mapping doc=compile_string("#define manual\n"+file->read())->tagdoc;
string imagecache=the_cache->documentation("cimg src='internal-roxen-robodog'");
|
2fafd2 | 2000-05-18 | Kenneth Johansson | |
|
739058 | 2000-06-01 | Martin Nilsson | | doc->cimg+=imagecache;
doc["cimg-url"]=imagecache;
return doc;
}
|
2fafd2 | 2000-05-18 | Kenneth Johansson | |
|
739058 | 2000-06-01 | Martin Nilsson | | #ifdef manual
|
2fafd2 | 2000-05-18 | Kenneth Johansson | | constant tagdoc=(["cimg":#"
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | <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>
|
2fafd2 | 2000-05-18 | Kenneth Johansson | |
<attr name='src' value='uri' required>
The path to the indata file.
<ex><cimg src='internal-roxen-robodog'/></ex>
</attr>
<attr name='data' value='imagedata'>
Insert images from other sources, e.g. databases through entities or
variables.
<ex type='box'>
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | <emit source='sql' query='select imagedata from images where id=37'>
<cimg data='&sql.imagedata;'/>
</emit>
|
2fafd2 | 2000-05-18 | Kenneth Johansson | | </ex>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>",
|
2fafd2 | 2000-05-18 | Kenneth Johansson | |
"cimg-url":#"<desc tag><short>This tag generates an URI to the manipulated
picture.</short> <tag>cimg-url</tag> takes the same attributes as
<tag>cimg</tag> including the image cache attributes. The use for the
tag is to insert image-URI's into various places, e.g. a submit-box.
</desc>
<attr name='src' value='uri' required>
The path to the indata file.
<ex><cimg-url src='internal-roxen-robodog'/></ex>
</attr>
<attr name='data' value='imagedata'>
Insert images from other sources, e.g. databases through entities or
variables.
<ex type='box'>
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | <emit source='sql' query='select imagedata from images where id=37'>
<cimg data='&sql.imagedata;'/>
</emit>
|
2fafd2 | 2000-05-18 | Kenneth Johansson | | </ex>
|
739058 | 2000-06-01 | Martin Nilsson | | </attr>",
]);
|
2e0a35 | 1999-12-09 | Martin Nilsson | | #endif
|
739058 | 2000-06-01 | Martin Nilsson | |
|
37bdda | 1999-05-18 | Per Hedbor | | void start()
{
the_cache = roxen.ImageCache( "cimg", generate_image );
}
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | mapping(string:function) query_action_buttons() {
|
5f13d5 | 2000-06-03 | Martin Nilsson | | return ([ "Clear cache":flush_cache ]);
}
void flush_cache() {
the_cache->flush();
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | }
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]));
}
|
37bdda | 1999-05-18 | Per Hedbor | | mapping generate_image( mapping args, RequestID id )
{
|
34a9b8 | 1999-08-06 | Peter Bortas | | if( args->data )
return roxen.low_decode_image( args->data );
else
return roxen.low_load_image( args->src, id );
|
37bdda | 1999-05-18 | Per Hedbor | | }
mapping find_internal( string f, RequestID id )
{
return the_cache->http_file_answer( f, id );
}
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | mapping get_my_args( mapping args, RequestID id )
|
37bdda | 1999-05-18 | Per Hedbor | | {
|
36eceb | 2000-01-30 | Per Hedbor | | mapping a=
([
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | "src":Roxen.fix_relative( args->src, id ),
|
37bdda | 1999-05-18 | Per Hedbor | | "quant":args->quant,
|
77926b | 2000-04-11 | Per Hedbor | | "crop":args->crop,
|
c52692 | 1999-05-18 | Per Hedbor | | "format":args->format,
"maxwidth":args->maxwidth,
"maxheight":args->maxheight,
"scale":args->scale,
"dither":args->dither,
|
b941aa | 1999-06-25 | Per Hedbor | | "gamma":args->gamma,
|
34a9b8 | 1999-08-06 | Peter Bortas | | "data":args->data,
|
37bdda | 1999-05-18 | Per Hedbor | | ]);
|
77926b | 2000-04-11 | Per Hedbor | |
|
1c10ca | 2000-07-05 | Per Hedbor | | if( a->src )
catch
{
|
1133a7 | 2000-07-07 | Henrik Grubbström (Grubba) | | array st = id->conf->stat_file(a->src, id) || file_stat(a->src);
if (st) {
a->mtime = (string) (a->stat = st[ST_MTIME]);
a->filesize = (string) st[ST_SIZE];
}
|
1c10ca | 2000-07-05 | Per Hedbor | | };
|
2fa8d5 | 2000-06-02 | Martin Nilsson | |
|
1c10ca | 2000-07-05 | Per Hedbor | | a["background-color"] = id->misc->defines->bgcolor || "#eeeeee";
|
77926b | 2000-04-11 | Per Hedbor | |
|
c52692 | 1999-05-18 | Per Hedbor | | foreach( glob( "*-*", indices(args)), string n )
a[n] = args[n];
|
77926b | 2000-04-11 | Per Hedbor | |
|
34a9b8 | 1999-08-06 | Peter Bortas | | return a;
}
|
a49dae | 2000-08-17 | Per Hedbor | | 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");
if( args->src && args->data )
RXML.parse_error("Only one of 'src' and 'data' may be specified\n");
return args;
}
class TagCimgplugin
{
inherit RXML.Tag;
constant name = "emit";
constant plugin_name = "cimg";
array get_dataset( mapping args, RequestID id )
{
mapping res = ([ ]);
mapping a = get_my_args( check_args( args ), id );
string data;
res->src = (query_internal_location()+the_cache->store( a,id ));
data = the_cache->data( a, id , 0 );
res["file-size"] = strlen(data);
res["file-size-kb"] = strlen(data)/1024;
res["data"] = data;
res |= the_cache->metadata( a, id, 0 );
return ({ res });
}
}
class TagCImg
{
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | inherit RXML.Tag;
constant name = "cimg";
constant flags = RXML.FLAG_EMPTY_ELEMENT;
|
a49dae | 2000-08-17 | Per Hedbor | | class Frame
{
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | inherit RXML.Frame;
|
a49dae | 2000-08-17 | Per Hedbor | | array do_return(RequestID id)
{
mapping a = get_my_args( check_args( args ), id );
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | args -= a;
args->src = query_internal_location()+the_cache->store( a,id );
if( mapping size = the_cache->metadata( a, id, 1 ) )
{
args->width = size->xsize;
args->height = size->ysize;
}
|
0023a6 | 2000-08-22 | Martin Nilsson | | int xml=!args->noxml;
m_delete(args, "noxml");
result = Roxen.make_tag( "img", args, xml );
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | return 0;
}
|
37bdda | 1999-05-18 | Per Hedbor | | }
}
|
698c12 | 1999-05-19 | Peter Bortas | |
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | class TagCImgURL {
inherit RXML.Tag;
constant name = "cimg-url";
constant flags = RXML.FLAG_EMPTY_ELEMENT;
|
a49dae | 2000-08-17 | Per Hedbor | | class Frame
{
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | inherit RXML.Frame;
|
a49dae | 2000-08-17 | Per Hedbor | | array do_return(RequestID id)
{
result = query_internal_location()+
the_cache->store(get_my_args(check_args( args ), id ),id);
|
2fa8d5 | 2000-06-02 | Martin Nilsson | | return 0;
}
}
|
698c12 | 1999-05-19 | Peter Bortas | | }
|