本帖最后由 flashercs 于 2025-4-17 14:14 编辑
回复 8# duoduo200
安装 https://imagemagick.org/script/download.php#windows
矩形变圆形.bat- @echo off
- cd /d "%~dp0"
- >nul chcp 65001
-
- magick mogrify -depth 8 -background none -colorspace sRGB -alpha set -channel A -fx "if(pow(i-(w-1)/2,2)/pow(w/2,2)+pow(j-(h-1)/2,2)/pow(h/2,2)>1&&a>0,0.005,s)" -verbose *.png
-
- @REM cmd /q /c "echo -depth 8 -background none -compose dstin & for %%A in (*.png) do echo "%%~A" -virtual-pixel none -print %%[f]\\n ( +clone -alpha transparent -strokewidth 0 -fill white -draw "ellipse %%[fx:w/2],%%[fx:h/2] %%[fx:w/2],%%[fx:h/2] 0,360" ) -composite -write "%%~A" +delete "|magick -script -
-
- pause
复制代码 圆形变矩形.bat- <#*,:
- @echo off&cd /d "%~dp0"&set "batchfile=%~f0"
- powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::UTF8 )) )"
- pause
- exit /b
- #>
- $utf8 = New-Object System.Text.UTF8Encoding -ArgumentList $false
- $OutputEncoding = [Console]::OutputEncoding = [Console]::InputEncoding = $utf8
- Get-ChildItem -Filter *.png | ForEach-Object {
- try {
- $alpha0 = (magick.exe $_.FullName -depth 8 -colorspace sRGB -alpha set -format "%[fx:a]" info:) -as [double]
- "$($_.Name) alpha0:$alpha0"
- if ($alpha0 -eq 0) {
- # if the background color is transparent,find the maincolor,and fill it to the background.
- $line = (magick.exe $_.FullName -depth 8 -colorspace sRGB -format "%[c]" histogram:info:) -notmatch '#[\dA-F]{6}00' | Sort-Object -Descending | Select-Object -First 1
- if ($line -and $line -match '#[\dA-F]+') {
- $maincolor = $Matches[0]
- "$($_.Name) maincolor:$maincolor"
- magick.exe $_.FullName -depth 8 -background $maincolor -layers flatten $_.FullName
- }
-
- } else {
- # if the background color is not transparent,set channel alpha to 100%
- magick.exe $_.FullName -depth 8 -colorspace sRGB -channel A -fx "1" $_.FullName
- }
- } finally {}
- trap {}
- }
复制代码
|