Skip to content

Instantly share code, notes, and snippets.

@nyanshiba
Last active June 9, 2019 14:01
Show Gist options
  • Save nyanshiba/3af6226dfb71412437ca7b2412c2a65a to your computer and use it in GitHub Desktop.
Save nyanshiba/3af6226dfb71412437ca7b2412c2a65a to your computer and use it in GitHub Desktop.
PNGをJPGに変換するやつ

ImageMagickのインストール(環境変数Pathへの登録)が必要

ファイルを指定する場合

pngjpg PATH

複数ファイルを指定する場合(9つまで)

pngjpg PATH PATH PATH PATH PATH PATH PATH PATH PATH

ディレクトリを指定する場合

pngjpg r DIR

モード選択
・yt: YouTubeのThumbnail用
・ds: Discordの8MB制限向け
・mq: そこそこいい感じに
・mqf: FHDでそこそこいい感じに

pngjpg.bat自体を環境変数Pathに通しておけば、Win+Rから実行できて便利だよ><

@echo off
rem 190408
rem 引数を表示
set cnt=0
setlocal enabledelayedexpansion
for %%a in ( %1 %2 %3 %4 %5 %6 %7 %8 %9 ) do (
if not %%a == "" (
set /a cnt+=1
echo !cnt!.%%a
)
)
setlocal disabledelayedexpansion
rem モード選択
set /p askmode=[yt: YouTubeThumbnail, ds: Discord, mq: MaxQuality, mqf: MaxQuality(FHD)]:
if "%~1" == "r" (
rem 1番目の引数が"r"の場合、2番目の引数のディレクトリ内を再帰的に処理する
echo recursive mode.
for %%a in ("%~2\*.*") do (
echo %%a
call :encode "%%a"
)
) else (
rem 9個までのファイルを再帰的に処理する
for %%a in ( %1 %2 %3 %4 %5 %6 %7 %8 %9 ) do (
if not %%a == "" (
echo %%a
call :encode "%%a"
)
)
)
pause
exit
:encode
if "%askmode%" == "yt" (
echo for YouTube Thumbnail mode.
magick convert -resize 1920x^> -quality 95 -define jpeg:extent=2MB -interlace jpeg %1 "%~dpn1.jpg"
) else if "%askmode%" == "ds" (
echo for Discord mode.
magick convert -resize 3840x^> -quality 95 -define jpeg:extent=8MB -interlace jpeg %1 "%~dpn1.jpg"
) else if "%askmode%" == "mq" (
echo for Max Quality mode.
magick convert -quality 95 -interlace jpeg %1 "%~dpn1.jpg"
) else if "%askmode%" == "mqf" (
echo for Max Quality mode.
magick convert -resize 1920x^> -quality 95 -interlace jpeg %1 "%~dpn1.jpg"
)
exit /b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment