在GIF中将PDF /图像转换为基于翻转的效果

时间:2015-09-23 18:21:26

标签: pdf imagemagick animated-gif flip

我想在GIF中将PDF或图像序列转换为基于翻转的效果(类似于下面的那种)。

enter image description here

有没有可用的软件可以用来产生这个输出?或者我是否必须使用imageMagicK编写脚本?请提出建议?

提前致谢!

1 个答案:

答案 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.gifpage1.gifpage2.gif ......

enter image description here

enter image description here

enter image description here

enter image description here

您将收到page3.gif

enter image description here

如果您的图书超过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 - generalss64 - set command一般在BATCH上。此外,一个名叫Alan Gibson的英国人非常有竞争力地使用IM,你可以看到他的脚本here,以及更普遍的here,以获得有关如何在Windows下有效使用IM的灵感。