答案 0 :(得分:1)
酷项目!这不是生产就绪的,经过军事处理的防弹代码,但是以下内容将完成大部分繁重工作,包括设置,附加单个页面,扭曲页面,最后将整个页面放在一起在动画GIF序列中。
因此,如果您从以下#!/bin/bash
################################################################################
# flipbook
# Mark Setchell
#
# Give me 4 pages as parameters and I create an animated GIF book out of them
# called book.gif.
#
# Requires ImageMagick
################################################################################
# Names of the 4 pages
p0=${1:-page0.gif} # Use first arg, or "page-0.gif" if none given
p1=${2:-page1.gif}
p2=${3:-page2.gif}
p3=${4:-page3.gif}
# Get width and height of images - I assume, but do not check all are identical sizes
read w h < <(convert "$p0" -format "%w %h" info: )
((twow=w+w))
# Layout first and last flat double-page spreads
convert "$p0" "$p1" +append frame0.png
convert "$p2" "$p3" +append frame4.png
# Make right page taller and thinner and save as "distorted.png"
((deltah=20*h/100))
((deltaw=20*w/100))
((hplusdeltah=h+deltah))
((wminusdeltaw=w-deltaw))
((hplus2deltah=h+deltah+deltah))
points="0,0 0,$deltah $wminusdeltaw,0 $wminusdeltaw,0 $wminusdeltaw,$hplus2deltah $wminusdeltaw,$hplus2deltah 0,$hplus2deltah 0,$hplusdeltah"
convert "$p1" +matte -virtual-pixel transparent \
-resize ${wminusdeltaw}x${hplus2deltah}! +repage \
-distort Perspective "$points" +repage distorted.png
# Make second frame by overlaying distorted right page ontop of pages 0 and 3
convert "$p0" "$p3" +append \
-bordercolor white -border 0x$deltah \
+repage \
distorted.png \
-geometry +${w}x \
-composite frame1.png
# Make left page taller and thinner and save as "distorted.png"
((deltaw=70*w/100))
((wminusdeltaw=w-deltaw))
points="0,0 0,0 $wminusdeltaw,0 $wminusdeltaw,$deltah $wminusdeltaw,$hplus2deltah $wminusdeltaw,$hplusdeltah 0,$hplus2deltah 0,$hplus2deltah"
convert "$p2" +matte -virtual-pixel transparent \
-resize ${wminusdeltaw}x${hplus2deltah}! +repage \
-distort Perspective "$points" +repage distorted.png
# Make third frame by overlaying distorted left page ontop of pages 0 and 3
convert "$p0" "$p3" +append \
-bordercolor white -border 0x$deltah \
+repage \
distorted.png \
-geometry +${deltaw}x \
-composite frame2.png
# Make left page taller and thinner and save as "distorted.png"
((deltaw=20*w/100))
((wminusdeltaw=w-deltaw))
points="0,0 0,0 $wminusdeltaw,0 $wminusdeltaw,$deltah $wminusdeltaw,$hplus2deltah $wminusdeltaw,$hplusdeltah 0,$hplus2deltah 0,$hplus2deltah"
convert "$p2" +matte -virtual-pixel transparent \
-resize ${wminusdeltaw}x${hplus2deltah}! +repage \
-distort Perspective "$points" +repage distorted.png
# Make fourth frame by overlaying distorted right page ontop of pages 0 and 3
convert "$p0" "$p3" +append \
-bordercolor white -border 0x$deltah \
+repage \
distorted.png \
-geometry +${deltaw}x \
-composite frame3.png
# Make final animation from frame0.png...frame4.png
convert -gravity center -delay 100 frame*.png -background white -extent ${twow}x${hplus2deltah} book.gif
开始,page0.gif
,page1.gif
和page2.gif
......
您将收到page3.gif
如果您的图书超过4页,您可以一次执行4本,然后非常简单地附加动画。
更新了答案
看起来你很遗憾不得不使用Windows - 这在BATCH中非常麻烦。我不是专家,但可以在BATCH中稍微解决一下。我认为上面的脚本很容易翻译。我会让你开始,但你需要自己做一些 - 如果你遇到问题,你可以随时提出一个新问题 - 问题是免费的!
脚本的第一部分只是选取命令行提供的参数,所以它看起来像这样:
book.gif
然后我们需要计算输入图像的宽度和高度,如下所示:
REM Pick up commandline parameters
set p0=%1
set p1=%2
set p2=%3
set p3=%4
REM Get width and height of images in variable "w" and "h"
FOR /F %%A IN ('identify -format "w=%%w\nh=%%h" %p0%') DO set %%A
内原始脚本中的所有内容都只是简单的数学,可以使用((..))
在BATCH中完成,所以这些行看起来像这样:
SET /A
将如下所示:
((twow=w+w))
((deltah=20*h/100))
其余的只是SET /A TWOW=w+w
SET /A DELTAH=20*h/100
命令 - 你需要在那里做几件事:
替换行末尾的行延续,因此将convert
更改为\
我使用^
或$variable
的位置,请将其替换为${variable}
加倍%variable%
个符号,%
变为%
将%%
更改为\(
- 我认为
将任何单引号^(
更改为双引号'
最好只是通过它来看看当你转换每一行时会发生什么,如果你不能解决它就会问另一个问题。
这些地方有一些好消息 - ss64 - general,ss64 - set command一般在BATCH上。此外,一个名叫Alan Gibson的英国人非常有竞争力地使用IM,你可以看到他的脚本here,以及更普遍的here,以获得有关如何在Windows下有效使用IM的灵感。