Last active
December 9, 2015 22:02
-
-
Save be5invis/2f8f79547e7dd238174e to your computer and use it in GitHub Desktop.
修本专用放大脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$input = $args[0] | |
$output = $input -replace '.(gif|png|jpg|jpeg)$','.2x.png' | |
echo "$input --> $output" | |
# 通过叠加在黑色和白色背景上来处理半透明的图片 | |
# 因为我又一次真特么要放大透明图 | |
$temp_black = [System.IO.Path]::GetTempFileName() + '.png' | |
$temp_black_2x = [System.IO.Path]::GetTempFileName() + '.png' | |
$temp_white = [System.IO.Path]::GetTempFileName() + '.png' | |
$temp_white_2x = [System.IO.Path]::GetTempFileName() + '.png' | |
# convert 为 imagemagick | |
convert $input -background white -flatten $temp_white | |
convert $input -background black -flatten $temp_black | |
# 以下两行请自行替换为你用的 w2x 命令 | |
# 扫图请把 --mode 改掉 | |
D:\apps\waifu2x-converter\waifu2x-converter_x64.exe --model_dir "D:\apps\waifu2x-converter\models" -i $temp_white -o $temp_white_2x --scale_ratio 2.0 --mode scale | |
D:\apps\waifu2x-converter\waifu2x-converter_x64.exe --model_dir "D:\apps\waifu2x-converter\models" -i $temp_black -o $temp_black_2x --scale_ratio 2.0 --mode scale | |
# alpha 计算公式:1 - w + b,RGB 计算公式 b[channel] / alpha | |
convert $temp_white_2x -negate $temp_black_2x -compose plus -composite '(' -clone 0 $temp_black_2x -compose divide_dst -composite ')' -swap '0,1' -alpha off -compose Copy_Opacity -composite $output | |
rm $temp_white,$temp_white_2x,$temp_black,$temp_black_2x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment