阿江 2018-11-07 14:43:35 139次浏览 1条回复 0 0 0

强大的linux太好用了,一条命令即可生成5万张缩图,这条命令就是:

[edger@centos7 wwwdir] #15> find -name "*.jpg" -exec convert -resize 300 {} {} \;

注意:命令最后面的\;不能少

为5万张大图片生成300px宽度的缩图,总用时10多分钟,详细步骤如下(双斜杠开头的是注释):

//查看图片目录img的大小
[edger@centos7 wwwdir] #14> du img -h --max-depth=0
9.2G	img
[edger@centos7 wwwdir] #15> pwd
/mywork/wwwdir
[edger@centos7 wwwdir] #16> 
//复制目录img为img_300
[edger@centos7 wwwdir] #19> \cp -rf img img_w300
//查看目录img_w300已生成:
[edger@centos7 wwwdir] #20> ll
total 8
drwxr-xr-x  4 edger edger   31 Nov  7 08:34 ./
drwxr-xr-x  3 edger edger   27 Jul 30 16:44 ../
drwxr-xr-x 51 edger edger 4096 Aug 13 11:02 img/
drwxr-xr-x 51 edger root     4096 Nov  7 08:39 img_w300/
//进入缩图目录:
[edger@centos7 wwwdir] #21> cd img_w300
//查看图片数量:
[edger@centos7 img_w300] #25> find -name "*.jpg" | wc -l
59410
[edger@centos7 img_w300] #26> find -name "*.png" | wc -l
431
[edger@centos7 img_w300] #27> find -name "*.gif" | wc -l
46
[edger@centos7 img_w300] #28> 
//将jpg图片宽度变为300px,高度等比例缩放:(此处耗时最多,耐心等待)
[edger@centos7 img_w300] #28> find -name "*.jpg" -exec convert -resize 300 {} {} \;
[edger@centos7 img_w300] #29> 
//将png图片宽度变为300px,高度等比例缩放:
[edger@centos7 img_w300] #29> find -name "*.png" -exec convert -resize 300 {} {} \;
[edger@centos7 img_w300] #30> cd ..
//查看缩图目录尺寸:2.7GB,缩小了一半多
[edger@centos7 wwwdir] #32> du img_w300 -h --max-depth=0
2.7G	img_w300
[edger@centos7 wwwdir] #33> 

OK,为5万张大图片生成300px宽度的缩图至此全部完成,用时10多分钟。

生成缩图时使用到了convert命令,安装ImageMagick即可:

//安装ImageMagic
[edger@centos7 do] #8> sudo yum install ImageMagick
......
......
  Verifying  : OpenEXR-libs-1.7.1-7.el7.x86_64                                        4/4

Installed:
  ImageMagick.x86_64 0:6.7.8.9-15.el7_2

Dependency Installed:
  OpenEXR-libs.x86_64 0:1.7.1-7.el7                ilmbase.x86_64 0:1.0.3-7.el7
  libwmf-lite.x86_64 0:0.2.8.4-41.el7_1

Complete!
[edger@centos7 do] #10>

//查看convert命令的帮助:
[edger@centos7 do] #23> convert
[edger@centos7 do] #23> convert --help
Version: ImageMagick 6.7.8-9 2016-06-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP    

Usage: convert [options ...] file [ [options ...] file ...] [options ...] file

Image Settings:
  -adjoin              join images into a single multi-image file
  -affine matrix       affine transform matrix
......
......
Miscellaneous Options:
  -debug events        display copious debugging information
  -help                print program options
  -list type           print a list of supported option arguments
  -log format          format of debugging information
  -version             print version information

By default, the image format of `file' is determined by its magic
number.  To specify a particular image format, precede the filename
with an image format name and a colon (i.e. ps:image) or specify the
image type as the filename suffix (i.e. image.ps).  Specify 'file' as
'-' for standard input or output.
[edger@centos7 do] #24

(全文完)

  • 回复于 19小时前

    ImageMagick还可以用来把pdf转换成图片, 用起来也非常的方便

    convert -density 100 -background white -alpha remove  -quality 100 1.pdf  1.jpg
    
您需要登录后才可以回复。登录 | 立即注册