gpt4 book ai didi

windows - 将 Unix ImageMagick 脚本转换为 Windows 批处理文件

转载 作者:可可西里 更新时间:2023-11-01 10:08:50 24 4
gpt4 key购买 nike

我有以下 bash 脚本 (.sh),它在 Unix 中运行良好。我想转换为批处理 (.bat) 文件以便与 ImageMagick for Windows 一起使用,但我在转换时遇到了一些麻烦。

Unix 脚本的原始 GIT 存储库:

https://github.com/AndreyChernyh/imagemagick-filters

适用于 Windows 的 ImageMagick 版本:

http://www.imagemagick.org/download/binaries/ImageMagick-6.7.0-Q16-windows.zip

earlybird.sh :

#!/bin/bash

SOURCE=$1

# Prepare
rm -f result.jpg source_copy.jpg mask.png
convert $SOURCE -fill rgba\(251,243,213,1.0\) -colorize 100% fill.jpg
convert assets/earlybird/mask.png -resize `identify -format "%wx%h" $SOURCE`\! mask.png
cp $SOURCE source_copy.jpg

# Run
convert fill.jpg $SOURCE -compose multiply -gravity center -composite - |
convert - -modulate 101,68,100 - |
convert - -gamma 1.19 - |
convert - -channel red +level 10.5%,100% - |
convert - -modulate 105,120 - |
convert - -modulate 100,83,100 - |
convert - -level 0%,92%,0.92 - |
convert mask.png - -compose ColorBurn -composite - |
convert mask.png - -compose Multiply -composite result.jpg

# Cleanup
rm -f source_copy.jpg fill.jpg

# Open
open $SOURCE result.jpg

这是我目前所拥有的,但它没有按预期工作,因为我不确定多个命令行参数的批处理文件等价物是什么:例如,“\”或“|”或者它是否可能。我在某处读到等效的插入符号“^”,但同样,我不是 100% 确定如何正确实现它。

@echo off

set SOURCE=%1

del result.jpg
del source_copy.jpg
del mask.png

convert.exe %SOURCE% -fill rgba(251,243,213,1.0\) -colorize 100% fill.jpg
convert.exe assets\earlybird\mask.png -resize 1024x768 mask.png

copy %SOURCE% source_copy.jpg

convert.exe fill.jpg %SOURCE% -compose multiply -gravity center -composite - ^
convert.exe - -modulate 101,68,100 - ^
convert.exe - -gamma 1.19 - ^
convert.exe - -channel red +level 10.5%,100% - ^
convert.exe - -modulate 105,120 - ^
convert.exe - -modulate 100,83,100 - ^
convert.exe - -level 0%,92%,0.92 - ^
convert.exe mask.png - -compose ColorBurn -composite - ^
convert.exe mask.png - -compose Multiply -composite result.jpg

del source_copy.jpg
del fill.jpg

工作代码:

这是我应用@Gabe 的回答后所做的。没有错误,它运行完美!

@echo off

set SOURCE=%1

del result.jpg
del source_copy.jpg
del mask.png

conv %SOURCE% -fill rgba(251,243,213,1.0) -colorize 100%% fill.jpg
conv assets\earlybird\mask.png -resize 604x453 mask.png

copy %SOURCE% source_copy.jpg

conv fill.jpg %SOURCE% -compose multiply -gravity center -composite - |^
conv - -modulate 101,68,100 - |^
conv - -gamma 1.19 - |^
conv - -channel red +level 10.5%%,100%% - |^
conv - -modulate 105,120 - |^
conv - -modulate 100,83,100 - |^
conv - -level 0%%,92%%,0.92 - |^
conv mask.png - -compose ColorBurn -composite - |^
conv mask.png - -compose Multiply -composite result.jpg

del source_copy.jpg
del fill.jpg

最佳答案

你很接近。我看到的大问题是你在 rgba(...) 中有一个额外的 \,你需要转义你的 % 符号(比如%%),并且你需要在续行符前加上|(如|^)。试试这个:

@echo off

set SOURCE=%1

del result.jpg source_copy.jpg mask.png

convert.exe %SOURCE% -fill rgba(251,243,213,1.0) -colorize 100%% fill.jpg
convert.exe assets\earlybird\mask.png -resize 1024x768 mask.png

copy %SOURCE% source_copy.jpg

convert.exe fill.jpg %SOURCE% -compose multiply -gravity center -composite - |^
convert.exe - -modulate 101,68,100 - |^
convert.exe - -gamma 1.19 - ^
convert.exe - -channel red +level 10.5%%,100%% - |^
convert.exe - -modulate 105,120 - |^
convert.exe - -modulate 100,83,100 - |^
convert.exe - -level 0%%,92%%,0.92 - |^
convert.exe mask.png - -compose ColorBurn -composite - |^
convert.exe mask.png - -compose Multiply -composite result.jpg

del source_copy.jpg fill.jpg

关于windows - 将 Unix ImageMagick 脚本转换为 Windows 批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6366682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com