Shell bulk Compress pictures within specified folder and subfolders

Source: Internet
Author: User

Shell bulk Compress pictures within specified folder and subfolders


The user uploads the picture, generally has not been compressed, causes the space to waste. Therefore, you need to write a program to find the folder and subfolders of the picture file (jpg,gif,png), the image is larger than a value compression processing.


The code is as follows:

#!/bin/bash# find picture files for folders and subfolders (jpg,gif,png), compress images larger than a value # configfolderpath= '/home/fdipzone/photo '   # Picture folder path maxsize= ' 1M '    # picture size agree value maxwidth=1280   # picture Max width maxheight=1280  # picture Max height quality=85      # picture quality # compression Processing # Param $folderPath Picture folder function compress () {    folderpath=$1    if [-d ' $folderPath "]; then for        file in $ (find" $f Olderpath "\ (-name" *.jpg "-or-name" *.gif "-or-name" *.png "\)-type f-size +" $maxSize "); Do            echo $file            # call ImageMagick resize picture            $ (convert-resize "$maxWidth" x "$maxHeight" "$file"-quality "$ Quality "-colorspace SRGB" $file ")        done    else        Echo ' $folderPath not exists '    fi}# Run Compresscompress "$folderPath" Exit 0


Shell bulk Compress pictures within specified folder and subfolders

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.