Skip to content

Instantly share code, notes, and snippets.

@DevSusu
Last active May 6, 2020 07:56
Show Gist options
  • Save DevSusu/73b05ff91ccd6e249ab379501e717eb9 to your computer and use it in GitHub Desktop.
Save DevSusu/73b05ff91ccd6e249ab379501e717eb9 to your computer and use it in GitHub Desktop.
Batch png to jpg Compress and Convert
find . -type f -name "*.png" -exec basename {} .png ';' | while read -r line ; do
$(convert $line.png pnm:- | mozcjpeg -quality 80 > jpg/$line.jpg)
done
find . -type f -name "*.png" -exec basename {} .png ';' | while read -r line ; do
$(convert $line.png -background white -alpha remove -alpha off pnm:- | mozcjpeg -quality 80 > jpg/$line.jpg)
done
@DevSusu
Copy link
Author

DevSusu commented Dec 16, 2019

Prerequisites

Mac OS 에서 Terminal(터미널) App을 열어 아래와 같이 명령어를 입력해주세요.

<some_version>은 brew install mozjpeg 명령 후 설치된 버전을 보고 입력해주셔야 합니다.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install imagemagick
brew install mozjpeg

ln -s /usr/local/Cellar/mozjpeg/<some_version>/bin/cjpeg /usr/local/bin/mozcjpeg

위 작업까지 완료되면,

convert_png2jpg.sh.zip 파일을 다운로드해서 jpg가 들어있는 폴더 안에 압축을 풀어줍니다.

jpg 라는 폴더를 만들어 줍니다.

image

해당 폴더에서 상단 Finder -> Services -> New Terminal at Folder 을 찾아서 눌러줍니다 (한글일 경우 다를 수 있습니다)

image

다시 열린 Terminal(터미널) 앱에 다음과 같이 입력하면 잠시 후 jpg 폴더에 작업이 완료됩니다.

chmod 700 convert_png2jpg.sh && ./convert_png2jpg.sh

image

감사합니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment