OpenWrt Forum Archive

Topic: Fast jpeg / jpg - thumbnail creation, epeg - library

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Fries43 wrote:

Has anyone tried to port epeg.library [1],[2] to openwrt,
or are there better methods out there?

It would be nice have such fast thumbnail-support in our
community-mesh for blogging and such things...

bye, Bastian /weimarnetz.de

[1] http://docs.enlightenment.org/api/epeg/html/
[2] http://search.cpan.org/~mcurtis/Image-Epeg-0.07/Epeg.pm

I tried this library, the idea is very good, this works very well to generate thumbnails, it is about 40 times faster than GD with php5 on my wrtsl54gs.
However the quality is not very good because the resampling is just 'nearest neighbor', and the thumbnails must be of the same aspect ratio of the input or will be shrink (I like square thumbnails).

My idea was just to have a fast binary to build thumbnails, so I extracted the interesting parts of the epeg library into a epeglite.c/.h files, coded a new smoothing resample algorithm and modified various other stuff to have a binary that only depends on libjpeg.

I can post the source code somewhere if you are interested.

Anael

I got some requests by e-mail about this small tool I wrote around epeg library.

So here is my package source (there is the source code inside). http://aorlinsk2.free.fr/openwrt/kamika … src.tar.gz

Just see that this binary is specific to my needs and then not very useful for the community in this form.

However the nicer algorithms I implemented for resizing are in the epeglite.c/.h files so you will take advantage of them if you just modify the main() of resizer.c to write your own resizer.

To see how I use this tool, here is my old PHP and new PHP code extracted from my self-written photo gallery:

function make_thumb($img, $out_file, $thumbsize)
{
        exec("fastthumb ".$thumbsize." ".escapeshellarg($img)." ".escapeshellarg($out_file));
}

function make_thumb_old($img, $out_file, $thumbsize)
{
        $img_in=ImageCreateFromJPEG($img);

        $ix=imagesx($img_in);
        $iy=imagesy($img_in);

        //create output image
        $img_out=ImageCreateTrueColor($thumbsize,$thumbsize);


        //size of square of selection
        $sqs=abs(min($ix,$iy));

        //random choose x and y position of extracting square
        srand((double)microtime()*1000000);
        $px=rand(0,$ix-$sqs);
        $py=rand(0,$iy-$sqs);

        ImageCopyResampled($img_out,$img_in,0,0,$px,$py,$thumbsize,$thumbsize,$sqs,$sqs);
        Imagejpeg($img_out,$out_file,90 /* jpeg quality */);

        ImageDestroy($img_in);
        ImageDestroy($img_out);
}

Anael

The discussion might have continued from here.