Linux 下通过命令生成缩略图并按规则重命名

Linux 下可以通过命令方式很方便的批量生成图片缩略图,这里需要用到的一个工具是ImageMagick。

ImageMagick是一个功能强大的图像工具,大多数linux发行版都会默认安装。(手动安装自行google)

缩略图转换命令如下:

convert head.jpg -sample 100x100 "head_100x100.jpg"

这是单个转换,将head.jpg 转换为长宽100×100大小的图片,并且重命名,将尺寸加到文件名中。

注意这里100×100是加在文件名中间位置。

通常的批量转换方式:

for img in `find ./ -name "*.jpg"`
do
convert $img -sample 200x150  "100x100_"$img
done

find ./ -name “*.jpg”  是获得当前目录及子目录下得所有jpg图片信息

如果只是当前目录不含子目录可以用 ls *.jpg

上面这段脚本转换后的文件名是   100x100_文件名.jpg  不怎么符合使用需求,通常需要的是:文件名_100x100.jpg

脚本做如下修改

for img in `find ./ -name "*.jpg"`
do
newimg=$(echo $img | cut -d. -f2);
convert $img -sample 100x100 "."$newimg"_100x100.jpg"
done

newimg=$(echo $img | cut -d. -f2);  这个是截取文件名和路径部分,也可以说是用来去掉扩展名.jpg

这两批量生成的文件名就符合需求了

不过前提是路径和文件名部分不能包含”.”  如果有需要再处理

19 Comments

  1. Education

    F*ckin’ awesome issues here. I’m very glad to peer your article. Thank you so much and i am having a look forward to contact you. Will you please drop me a mail?

    Reply
  2. Education

    Great blog here! Also your website loads up fast! What web host are you using? Can I get your affiliate link to your host? I wish my site loaded up as fast as yours lol

    Reply
  3. Education

    It’s actually a nice and helpful piece of information. I’m glad that you shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

    Reply
  4. Business Service

    Hey There. I found your blog using msn. This is a very well written article. I’ll make sure to bookmark it and return to read more of your useful information. Thanks for the post. I will certainly comeback.

    Reply
  5. fire

    Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.|

    Reply
  6. Education and Training

    I’ve read some just right stuff here. Certainly worth bookmarking for revisiting. I surprise how so much attempt you place to create the sort of great informative web site.

    Reply
  7. Education and Training

    A lot of thanks for each of your effort on this blog. My mom take interest in doing internet research and it’s really easy to understand why. I notice all relating to the compelling method you deliver worthwhile information through your web blog and therefore boost contribution from visitors on that matter and our daughter is actually studying a whole lot. Take pleasure in the rest of the new year. You’re the one conducting a superb job.

    Reply
  8. it consulting firms

    My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on various websites for about a year and am nervous about switching to another platform. I have heard great things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any help would be greatly appreciated!

    Reply
  9. Car Service

    hello there and thank you for your info – I’ve definitely picked up something new from right here. I did however expertise several technical issues using this web site, since I experienced to reload the web site a lot of times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your high quality score if advertising and marketing with Adwords. Anyway I am adding this RSS to my email and can look out for much more of your respective intriguing content. Make sure you update this again very soon..

    Reply
  10. Vitamin

    I have recently started a site, the information you offer on this web site has helped me tremendously. Thank you for all of your time & work.

    Reply
  11. Civil Law

    Hi there very nice blog!! Man .. Excellent .. Amazing .. I will bookmark your web site and take the feeds additionally¡KI am glad to seek out so many helpful info right here in the put up, we need develop more techniques in this regard, thank you for sharing. . . . . .

    Reply
  12. Michaelbruth

    If you want ones work to become published swiftly and with no blunders the location for you. Our low-budget custom essay crafting assistance is often effective for each scholar who has no time or want to handle essays. We recognize that students right away really need to offer with significantly more courses, books, papers and professors. Which is why we want for making it a bit simpler for yourself with our essay creating support. Not everyone is prepared to sit for several hours and power their creativity and creativeness to do the things they refuse to carry out.
    custom writing

    Reply
  13. Travel International

    I’ve been browsing online more than three hours today, but I never found any interesting article like yours. It is lovely value sufficient for me. Personally, if all web owners and bloggers made excellent content as you probably did, the internet might be much more helpful than ever before.

    Reply
  14. Car & Automotive

    You made some nice points there. I looked on the internet for the subject and found most people will agree with your website.

    Reply
  15. Car & Automotive

    You made a few good points there. I did a search on the topic and found a good number of persons will go along with with your blog.

    Reply

Leave a Comment

电子邮件地址不会被公开。 必填项已用*标注