返回列表 发帖
回复 14# buyiyang


    大佬,我用原PNG图片和透明底PNG图片还是不行,麻烦大佬再给看看,上面有图片样张的百度网盘链接,方便您调试,多谢多谢!

[img][/img]

TOP

本帖最后由 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 -
pauseCOPY
圆形变矩形.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 {}
}COPY
微信:flashercs
QQ:49908356

TOP

回复 16# duoduo200


    你发的图中左侧filled后缀的文件就是处理后的,与你预期有什么不符?

TOP

回复 17# flashercs


    大佬你好,感谢再次出手!实测下来不知道我安装的软件不对,还是哪个顺序没对,测试了两次都是无法圆变方形。
[img][/img]

不知道能不能最终能不能实现如开篇帖子里的无损变成圆转方形,期待您的回复,谢谢。

TOP

回复 18# buyiyang


    嗯嗯,谢谢大佬。主要是没有变成无损的方形,如下图这样

TOP

回复 19# duoduo200


    bat的逻辑就是这样的,读取使用最多的颜色填充为背景

我估计你的意思是要把填充后的外围的圆边去掉

QQ 20147578

TOP

这问题我一看就闪的远远的
因为以前做过类似的折腾,你没办法不经过AI而智能地脑补一些背景线条的延伸,总会有各种情况(背景色块、纹理、背景渐变,渐变又分为不同角度、线性、径向、锥型 。。。 )。
[url=][/url]

TOP

我还是要纠正一下描述,
这叫无损?这分明是要脑补呀。
[url=][/url]

TOP

回复 23# 523066680


    感谢版主指点,但有没有PS的脚本,可以自动变形成圆变方?

TOP

返回列表