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

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

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

43 thoughts on “Linux 下通过命令生成缩略图并按规则重命名”

  1. I’m gone to convey my little brother, that he should also go to see this web site on regular basis to
    take updated from most recent gossip.

  2. What’s Going down i’m new to this, I stumbled upon this I have
    discovered It absolutely useful and it has helped me out loads.
    I’m hoping to contribute & aid different customers like its helped me.
    Great job.

  3. You’re so interesting! I don’t believe I’ve read a single thing like that before.
    So great to find another person with a few genuine thoughts on this topic.
    Really.. many thanks for starting this up. This web site is
    something that is needed on the web, someone with a bit of originality!

  4. Nice post. I was checking continuously this blog and
    I’m impressed! Extremely useful info specially the last part
    🙂 I care for such information much. I was seeking this certain information for
    a very long time. Thank you and best of luck.

  5. I enjoy what you guys are up too. This sort of clever work and
    exposure! Keep up the very good works guys I’ve added you guys to my
    blogroll.

  6. I’m impressed, I have to admit. Rarely do I come across a blog that’s both educative and amusing, and let me tell you, you
    have hit the nail on the head. The issue is something which not enough people are speaking intelligently about.
    Now i’m very happy that I came across this during my hunt for
    something relating to this.

  7. It’s perfect time to make some plans for the future and it is time to be
    happy. I’ve read this post and if I could I want to suggest you some fascinating issues or advice.
    Maybe you can write next articles referring to this
    article. I wish to read more issues about it!

  8. Howdy just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Opera.

    I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I figured I’d post
    to let you know. The design and style look great
    though! Hope you get the issue resolved soon. Many thanks

  9. It is the best time to make some plans for the future and it is time to be
    happy. I have read this post and if I could I desire to suggest you few interesting
    things or tips. Perhaps you can write next articles referring to this article.
    I desire to read more things about it!

  10. Hello, I think your site might be having browser compatibility issues.
    When I look at your blog in Ie, it looks fine
    but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, excellent
    blog!

  11. hello there and thank you for your information – I have certainly picked up something new from right here.

    I did however expertise some technical points using this website, as I experienced to reload the
    website many 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 slow loading instances times will sometimes affect your placement in google
    and can damage your quality score if ads and marketing with Adwords.

    Well I am adding this RSS to my email and could look out
    for a lot more of your respective interesting content.
    Make sure you update this again soon.

  12. Neat blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my blog shine.

    Please let me know where you got your design. Appreciate it

  13. Attractive component of content. I simply stumbled
    upon your site and in accession capital to say that I get in fact
    loved account your weblog posts. Any way I’ll be
    subscribing for your feeds or even I achievement you get right of
    entry to constantly rapidly.

  14. I am really enjoying the theme/design of your website.
    Do you ever run into any web browser compatibility problems?
    A small number of my blog audience have complained about my website not working correctly in Explorer but looks great in Firefox.
    Do you have any tips to help fix this issue?

  15. I love your blog.. very nice colors & theme. Did you make this
    website yourself or did you hire someone to do it for you?
    Plz respond as I’m looking to construct my own blog
    and would like to find out where u got this from.
    thank you

  16. An outstanding share! I’ve just forwarded this onto a friend who was conducting
    a little research on this. And he actually bought me breakfast due
    to the fact that I discovered it for him… lol. So let me reword this….

    Thanks for the meal!! But yeah, thanx for spending the time to talk about this topic
    here on your internet site.

  17. Howdy, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam
    feedback? If so how do you protect against it,
    any plugin or anything you can advise? I get so much lately it’s driving me mad
    so any help is very much appreciated.

  18. Hello! I could have sworn I’ve been to this website before but after reading
    through some of the post I realized it’s new to me. Nonetheless,
    I’m definitely happy I found it and I’ll be bookmarking and checking back often!

  19. It’s really a great and useful piece of information. I am glad that you shared this useful information with us.
    Please stay us informed like this. Thank you for sharing.

  20. Superb post however , I was wondering if you could write a litte more on this topic?
    I’d be very grateful if you could elaborate a little
    bit more. Bless you!

  21. Thanks , I have recently been looking for information approximately this
    topic for a long time and yours is the best I’ve came upon so far.
    However, what concerning the conclusion? Are you certain about the source?

  22. Fantastic blog! Do you have any tips for aspiring writers?
    I’m hoping to start my own site soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go for a paid option? There are so many
    choices out there that I’m completely overwhelmed .. Any suggestions?

    Thanks a lot!

  23. Undeniably believe that which you said. Your favorite justification seemed to be on the web the simplest thing to be aware of.
    I say to you, I definitely get annoyed while
    people think about worries that they plainly do not know about.
    You managed to hit the nail upon the top
    and defined out the whole thing without having side-effects , people can take a
    signal. Will probably be back to get more. Thanks

  24. Valuable information. Lucky me I found your website unintentionally, and I am surprised why this coincidence did not came about in advance!
    I bookmarked it.

  25. Hey! I know this is kinda off topic but I was wondering which blog platform are you using for this website?
    I’m getting fed up of WordPress because I’ve had
    issues with hackers and I’m looking at alternatives for
    another platform. I would be awesome if you could point me
    in the direction of a good platform.

  26. After I initially left a comment I appear to have clicked the -Notify me when new comments are added-
    checkbox and from now on every time a comment is added I get four
    emails with the exact same comment. Is there a way you are able to remove me from that service?
    Kudos!

  27. Hi there everybody, here every person is
    sharing these know-how, thus it’s pleasant to read this website, and
    I used to pay a visit this weblog everyday.

  28. cheap jerseys
    If you want to move in even though the problems have not been fixed
    yet, then get an agreement in writing signed by the landlord which lists the repairs needed and gives a
    date when the repairs need to be done.Sign a move in checklist.
    Even if you do a walk through of the apartment and find
    no major problems, make sure that you and the landlord
    sign a move in checklist that describes the condition of the unit.
    If the landlord will not sign a checklist, then make your own checklist, sign and date
    it, mail it to the landlord, and keep a copy for yourself.

    wholesale jerseys Some of us rise to the occasion, while others are clearly not up to
    the challenge and wither away like an undesirable species.

    In relationships, the more a man passes a woman’s test, the more control and intimacy they achieve with their partner.
    Women want men who are in control of themselves, yet slightly out of control; a confident, independent individual who excels
    in different arenas of life. wholesale jerseys

    wholesale jerseys Furthermore, public safety unions, and police unions
    in particular, are often quite conservative in their
    politics. And in the age of Occupy, stop and frisk, and increasingly visible police brutality, law enforcement’s
    infatuation with its own power and its integral role in preserving the social status quo have become clearer than ever.

    As a result, the ideological disconnect between police and the left is widening.
    wholesale jerseys

    wholesale jerseys And finally, also from the State of New Jersey,
    the most ridiculous way to get a DUI: driving
    a Zamboni at an ice rink. A Zamboni is in approximately four ton ice cleaning machine
    used on indoor and outdoor rinks. If you have ever been to a hockey
    game the Zamboni is that giant ridiculous square
    machine that is used to bus the ice between periods.
    As gang related violent crimes reach new highs in Orange County, Sheriff Brad Gates is proposing a $400,000
    prevention program that stresses gang education and awareness on a countywide scale.
    Called Project No Gangs, the proposal will go before the Board
    of Supervisors on Tuesday for consideration. The project,
    developed by the Orange County Chiefs of Police Sheriff’s Assn.
    wholesale jerseys

    Cheap Jerseys free shipping Experts suggest that the best time to buy dwarf bunnies is when they are three to four months old.
    If you are getting a male dwarf bunny, ensure that it
    is spayed or neutered. Do not fathom keeping two males together as
    they view each other as competition, even in the
    absence of a female of the species. “I did a lot of that last year. Me and Stephen would talk about everything, every drive, every play, really. So I don’t expect any different this year.”
    Williams said his surgically repaired right
    knee is about 85 percent. Cheap Jerseys free shipping

    wholesale jerseys Traditional Chinese medicine (TCM) includes
    acupuncture and Chinese herbal medicine. It has successfully treated infertility, gynecological, male factor,
    as well as many other illnesses and health problems
    for over 5,000 years. Western medicine, by comparison, is just over
    200 years old. Our job as the leaders to get everyone on the same page.
    We been through it before as well as a few of the other veterans.
    It shouldn be too hard to get everyone ready. wholesale jerseys

    wholesale jerseys I was confirmed Protestant. She was
    confirmed Catholic. We are both children of the Sixties.
    After a much publicised move to the Luxembourg based Leopard Trek team
    over the winter the Schleck brothers Andy and Frank again headed into 2011
    full of optimism. The nearly man of the Tour de France in recent years, Andy spent the early season honing
    his form with the sole purpose of peaking in three weeks in July.
    That meant seemingly lacklustre performances at Tirreno Adriatico and
    the Vuelta al Pais Vasco, as well as a trip to California which, two months out and against reduced competition, could only yield eighth overall.
    wholesale jerseys

    wholesale nfl jerseys As a career soldier, and a general in charge of the continental army,
    Washington did have a few signature pieces of
    gear that he brought into the field with him. Washington had a pair of
    pistols made specifically for his use, and he was never without his cavalry
    saber. All three weapons are of masterwork, museum quality.
    During my visit, I observed a handsome young man happily helping women try on the coats and I finally stopped and asked who he was.
    Turned out to be Laparka head designer, Joseph
    Tassoni, an Oakville native, Ryerson grad. Tassoni is young, but already well seasoned in design: he
    held numerous spots in fashion design, production and marketing posts, including at Joseph Mimran Assoc wholesale nfl jerseys.

  29. Features Pricing Support Blog Free Trial Log In Buy followers Exclusive & Real Instagram followers! Krootez and you can buy automatic Instagram likes with monthly subscription. You can arrange your own package with as many views as you need.

发表评论

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