[epeg] is a super-fast library for resizing JPEGs. It offers an improvement of at least an order of magnitude over other known libraries like '''ImageMagick'''. Here are some numbers indicative of its speed: $ time ./tclepeg test.jpeg test.jpg real 0m0.063s user 0m0.060s sys 0m0.000s $ time convert -resize 426x640 test.jpeg test.jpg real 0m1.158s user 0m1.048s sys 0m0.052s In the above example the improvement is 18 fold. ''test.jpeg'' is a 2592x3888 image that is resized to a 426x640 one using the [epeg] library. '''Convert''' is ImageMagick's convert utility. It took ''epeg'' 63 msec to do the conversion against 1158 msec for ImageMagick. These timings include reading/writing to disk. '''tclepeg''' takes about 1msec to do the conversion on the same system. [tclepeg] is a first effort to bring '''epeg''''s functionality to TCL by means of a binary linux library that can be [load]ed into a TCL program. Size options are not yet parsed and the quality value is fixed, but this initial C code is posted here with the hope that more competent tclers may step in to improve it. ---- **C code for the tclepeg library** The library provides a TCL command ''epeg'' that takes as an argument JPEG image data. In the code below the output is fixed to 320x240px, 75% JPEG quality. See [epeg] for a summary of possible options (not yet implemented). Compiles on an Ubuntu Linux machine. /* * tclepeg.c -- A fast JPEG resize (reduction) Tcl C extension based on the epeg library * For a source repository of epeg look in : * http://maemo.gitorious.org/maemo-af/epeg * http://svn.enlightenment.org/svn/e/OLD/epeg/ * * Adapted to tcl by D.Zachariadis, Dec. 2011 * */ #include #include #include "Epeg.h" static int Tclepeg_Cmd(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if(objc < 2) { Tcl_SetObjResult(interp, Tcl_NewStringObj("wrong # args. Should be epeg ?option value ...? jpegdata", -1)); } int sizei, sizeo; unsigned char *imi, *imo; Epeg_Image *im; imi = Tcl_GetByteArrayFromObj(objv[objc-1], &sizei); imo = (unsigned char *)malloc(sizei); // do image resize with epeg im = epeg_memory_open (imi,sizei); epeg_decode_size_set (im, 320, 240); epeg_quality_set (im, 75); epeg_thumbnail_comments_enable (im, 1); epeg_memory_output_set (im, &imo, &sizeo); epeg_encode (im); epeg_close (im); // resize allocated output image memory to free excessive memory imo = realloc(imo, sizeo); // prepare tcl command output Tcl_Obj * timo = Tcl_NewByteArrayObj(imo, sizeo); Tcl_SetObjResult(interp, timo); free(imo); return TCL_OK; } /* * Tclepeg_Init -- Called when Tcl loads the extension. */ int DLLEXPORT Tclepeg_Init(Tcl_Interp *interp) { if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) { return TCL_ERROR; } /* changed this to check for an error - GPS */ if (Tcl_PkgProvide(interp, "epeg", "0.1") == TCL_ERROR) { return TCL_ERROR; } Tcl_CreateObjCommand(interp, "epeg", Tclepeg_Cmd, NULL, NULL); return TCL_OK; } Compile using: gcc -shared tclepeg.c libepeg.a -ljpeg -o tclepeg.so ''libepeg.a'' and ''libjpeg'' have to be in the same directory with tclepeg.c or else their path should be changed so that the compiler knows where to find them. Usage example: load ./tclepeg.so # read in a JPEG image set fd [open test.jpeg] fconfigure $fd -translation binary set img [read $fd] close $fd # write reduced image set fd [open out.jpeg w] fconfigure $fd -translation binary # let tclepeg do the work puts -nonewline $fd [epeg $img] close $fd provided the ''tclepeg.so'' library is in the present working directory directory. You are welcome to improve the above code and post it here. <>Image Processing