O boskości PILa słów kilka
14 July 2008
Comments
W robocie pojawiło się zadanko określenia co szybciej zrobi miniatury z dużych JPEGów z aparatów. Serwis napisany jest w PHP i przechodzi obecnie przeobrażenia :) Miniatury robi w GD/PHP co jest bardzo wolne... Pod testy podszedł PIL, ImageMagick przez "convert" i MagicWand w PHP, GD... oraz EPEG. Wyniki robienia miniatur z 45MB fotek z aparatu (duża rozdzielczość i rozmiar):
- ImageMagick convert Resize: 28,3s (zachowuje dane exif i inne śmieci)
- ImageMagick convert Thumbnail: 15,3s (to należy stosować)
- PIL: 3,2s
- EPEG: 1,9s
Jedyny problem jaki napotkałem to wyostrzanie, które jakby nie chciało zadziałać:
im = Image.open(source)
im.thumbnail((width, heigth), Image.ANTIALIAS)
im.filter(ImageFilter.SHARPEN)
im.save(thumb, "JPEG",quality=quality)
#include <stdlib.h>
#include <unistd.h>
#include <Epeg.h>
#define PROGRAM "ethumber"
int
main(int argc, char **argv)
{
Epeg_Image * image;
int ch, height, quality, width;
char *input, *output;
/* Default values - can be overidden */
quality = 80;
height = 125;
width = 125;
output = "thumb.jpg";
while ((ch = getopt(argc, argv, "h:i:o:q:w:")) != -1) {
switch (ch) {
case 'h':
height = atoi(optarg);
break;
case 'i':
input = optarg;
break;
case 'o':
output = optarg;
break;
case 'q':
quality = atoi(optarg);
break;
case 'w':
width = atoi(optarg);
break;
default:
exit (0);
}
}
image = epeg_file_open(input);
if (!image) {
exit (0);
}
epeg_decode_size_set(image, width, height);
epeg_quality_set (image, quality);
epeg_file_output_set(image, output);
epeg_encode(image);
epeg_close(image);
return 0;
}
RkBlog
Comment article