`

GraphicsMagick生成缩略图性能优化

 
阅读更多

 

 

To make a thumbnail of a JPEG image, use:

    gm convert -size 120x120 cockatoo.jpg -resize 120x120 +profile "*" thumbnail.jpg

 

-size 参数说明

------------------------------------------

原文:

In this example, '-size 120x120' gives a hint to the JPEG decoder that the image is going to be downscaled to 120x120, 

allowing it to run faster by avoiding returning full-resolution images to GraphicsMagick for the subsequent resizing operation. 

The '-resize 120x120' specifies the desired dimensions of the output image. 

It will be scaled so its largest dimension is 120 pixels. 

The '+profile "*"' removes any ICM, EXIF, IPTC, or other profiles that might be present in the input and aren't needed in the thumbnail.

 

译文:

在这个例子中,'-size 120x120'给了JPEG解码器一个暗示,图像将会缩减到120x120,

允许它运行得更快通过避免返回GraphicsMagick全分辨率图像对后续的调整操作。

'-resize 120x120'指定理想的输出图像的尺寸。

这将是按比例缩小的所以它的最大尺寸是120像素。

'+profile "*"' 删除任何ICM,EXIF,IPTC或其他资料,可能会出现在输入和不需要的缩略图。

 

 

-size 效果测试 

------------------------------------------

测试环境:

OS: MAC OS X 10.7

CPU:i5 2410(双核4线程)

GM:version 1.3.7 未使用多线程(默认安装未开启openMP) 

 

大图片测试 

-----------------------------------

gm identify a.jpg

a.jpg JPEG 3040x1824+0+0 DirectClass 8-bit 2.1M 0.000u 0:01

 

gm benchmark -iterations 100 -stepthreads 1 convert  a.jpg -resize 100x100 +profile "*" a1.jpg  (耗时466ms)

Results: 1 threads 100 iter 46.64s user 46.64s total 2.144 iter/s 2.144 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 100x100 a.jpg -resize 100x100 +profile "*" a2.jpg (耗时47ms)

Results: 1 threads 100 iter 4.72s user 4.71s total 21.231 iter/s 21.186 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  a.jpg -resize 500x500 +profile "*" a3.jpg  (耗时532ms)

Results: 1 threads 100 iter 53.15s user 53.40s total 1.873 iter/s 1.881 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 500x500 a.jpg -resize 500x500 +profile "*" a4.jpg (耗时130ms)

Results: 1 threads 100 iter 13.06s user 13.06s total 7.657 iter/s 7.657 iter/cpu 1.00 speedup 1.000 karp-flatt

 

 

小图片测试 

-----------------------------------

gm identify b.jpg

b.jpg JPEG 1024x768+0+0 DirectClass 8-bit 125.4K 0.000u 0:01

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -resize 100x100 +profile "*" b1.jpg  (耗时68ms)

Results: 1 threads 100 iter 6.79s user 6.79s total 14.728 iter/s 14.728 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 100x100 b.jpg -resize 100x100 +profile "*" b2.jpg (耗时8.4ms)

Results: 1 threads 100 iter 0.83s user 0.84s total 119.048 iter/s 120.482 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -resize 500x500 +profile "*" b3.jpg  (耗时102ms)

Results: 1 threads 100 iter 10.21s user 10.22s total 9.785 iter/s 9.794 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 500x500 b.jpg -resize 500x500 +profile "*" b4.jpg (耗时100ms)

Results: 1 threads 100 iter 10.24s user 10.26s total 9.747 iter/s 9.766 iter/cpu 1.00 speedup 1.000 karp-flatt

 

 

小图片测试 

-----------------------------------

gm identify b.jpg

b.jpg JPEG 1024x768+0+0 DirectClass 8-bit 125.4K 0.000u 0:01

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -sample 100x100 +profile "*" s1.jpg  (耗时16ms)

Results: 1 threads 100 iter 1.64s user 1.65s total 60.606 iter/s 60.976 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 100x100 b.jpg -sample 100x100 +profile "*" s2.jpg  (耗时4.3ms)

Results: 1 threads 100 iter 0.43s user 1.51s total 66.225 iter/s 232.558 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -sample 500x500 +profile "*" s3.jpg  (耗时26.5ms)

Results: 1 threads 100 iter 2.65s user 2.65s total 37.736 iter/s 37.736 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 500x500 b.jpg -sample 500x500 +profile "*" s4.jpg  (耗时26.4ms)

Results: 1 threads 100 iter 2.64s user 2.64s total 37.879 iter/s 37.879 iter/cpu 1.00 speedup 1.000 karp-flatt

 

小图片测试 

-----------------------------------

gm identify b.jpg

b.jpg JPEG 1024x768+0+0 DirectClass 8-bit 125.4K 0.000u 0:01

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -thumbnail 500x500 +profile "*" t1.jpg  (耗时41ms)

Results: 1 threads 100 iter 4.11s user 4.22s total 23.697 iter/s 24.331 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 500x500 b.jpg -thumbnail 500x500 +profile "*" t2.jpg  (耗时40ms)

Results: 1 threads 100 iter 4.06s user 4.06s total 24.631 iter/s 24.631 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  b.jpg -thumbnail 500x500 +profile "*" t3.jpg  (耗时41ms)

Results: 1 threads 100 iter 4.12s user 4.13s total 24.213 iter/s 24.272 iter/cpu 1.00 speedup 1.000 karp-flatt

 

gm benchmark -iterations 100 -stepthreads 1 convert  -size 500x500 b.jpg -thumbnail 500x500 +profile "*" t4.jpg  (耗时40ms)

Results: 1 threads 100 iter 4.06s user 4.07s total 24.570 iter/s 24.631 iter/cpu 1.00 speedup 1.000 karp-flatt

 

 

总结

------------------------------------------

1、适用于生成小于300x300的小尺寸缩略图。

2、适用于原图与输出图片尺寸差距较的场景。

3、需要提前了解输入的原图的尺寸范围,应大于输出图片的尺寸。如果原图尺寸小于 -size width x height,反到无性能优化效果。

 

参考:http://www.graphicsmagick.org/convert.html

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics