convert animation (using postscript pages as frames)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

convert animation (using postscript pages as frames)

Post by forkosh »

I can already get the animation I want with
> convert -delay 0 -loop 0 eachframe*.gif animation.gif
using many eachframe*.gif input files. But what I'd like to do instead of many gif input files, is have one postscript input file that contains many showpage's with one frame on each page. And then some convert -magic so that
> convert -delay 0 -loop 0 -magic allframes.ps animation.gif
does the same thing, but with just that one input file. Is there any way to do that, or anything like that?
Thanks, John <john@forkosh.com>
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: convert animation (using postscript pages as frames)

Post by whugemann »

You can refer to a single page in a PDF file by "somefile.pdf[0]" and so on. This probably works for PostScript files as well. So you could possibly somehow just loop through your PDF file by use of a script. This should at least work if you use temporary files, converting the single pages first to, say, PNGs and then combine them to a GIF by using wildcards in your Convert command.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert animation (using postscript pages as frames)

Post by fmw42 »

I do not think you need to do anything. The following works for me.

convert lena2.jpg zelda3.jpg checks.jpg 1test.ps
convert -delay 50 1test.ps -loop 0 1test.gif

1test.gif animates just fine.


or try
convert -delay 50 1test.ps -coalesce -loop 0 1test.gif
or
convert -delay 50 1test.ps +adjoin -loop 0 1test.gif


I am on IM 6.7.8.8 Q16 Mac OSX Snow Leopard
User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

Re: convert animation (using postscript pages as frames)

Post by forkosh »

Thanks for the suggestions, whugemann and fmw42. I could pretty easily "loop through" as whugemann suggested, extracting one page at a time and then re-combining them all as an animation. But that would still involve lots of intermediate tmp files to be rm'ed afterwards. And the whole exercise was to avoid that, especially avoid the housekeeping involved cleaning it up, and especially if the script failed in the middle for any reason. It's running as an online cgi, so such failures could end up leaving lots and lots (and lots...) of garbage lying around before I finally noticed what was going on.

Fortunately, though, fmw42's suggestion definitely answers the question, i.e., "Don't need to do anything" is well within my skill set:). Sorry for bothering you guys if it's really that easy. That seemed so unlikely to me that I didn't even bother trying fmw42's kind of experiment before posting the question. The cgi "script" is actually a C program that generates the postscript, so it'll take me a while to rewrite the pieces necessary for it to emit one file with many pages rather than many files with one page each (what it does now). But I'll eventually followup here again to report the outcome when it's finally running.

Meanwhile, I was vaguely aware that the command-line order of files and -options is more significant for convert than for most programs. But I'd thought that what I originally posted
> convert -delay 0 -loop 0 eachframe*.gif animation.gif
was okay because, as far as I could tell, it's worked okay for me that way so far. But fmw42's syntax
> convert -delay 50 1test.ps -loop 0 1test.gif
> convert -delay 50 1test.ps -coalesce -loop 0 1test.gif
> convert -delay 50 1test.ps +adjoin -loop 0 1test.gif
suggests he knows something (probably lots of things) I don't. The man page stuff about that wasn't very clear to me. Is there some link to a more straightforward discussion about it?
Thanks again, John <john@forkosh.com>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert animation (using postscript pages as frames)

Post by fmw42 »

User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

Re: convert animation (using postscript pages as frames)

Post by forkosh »

Thanks, Fred. Those /Usage/basics/ links are indeed easier to read/understand than whatever it was I'd been reading (I'd just tossed a few relevant words at google and browsed through whatever looked good from what it coughed up, but can't recall exactly what that was).
User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

Re: convert animation (using postscript pages as frames)

Post by forkosh »

As promised above, I'm following up to "report the outcome after it's working".
A rather large 5MB (click only if you really want to see it) animation produced using Fred's suggestion is at
> http://www.forkosh.com/decorative/decofweek.gif
and the corresponding postscript from which it was convert'ed is at (you guessed it)
> http://www.forkosh.com/decorative/decofweek.ps
You can see the .ps file contains lots of "%%Page n n......showpage"s, separating each frame, and then the very simple command
> convert -delay 0 -loop 0 decofweek.ps decofweek.gif
renders the gif just like Fred promised.

One little problem... that convert command took 6min52secs on an i7-920 running linux slackware. One reason it takes so long is that I can't seem to get a transparent background. Right now, the first frame contains one line, the second frame contains two lines, ..., and the hundredth/last frame contains 100 lines. But the idea was that each frame would contain only one line -- the first frame containing only the first line ... the hundredth frame only the 100th line. And with a transparent background that would build up the complete image. But with an opaque background I have to put all lines on each frame. And that's a total of 5050 lines (1+2+...+100=5050) instead of just 100 lines, so convert has lots more work to do (and renders a much larger gif file, too). Is there any way to convert ps-->gif and force a transparent background? I fooled around with several -switches, but nothing I tried had any effect whatsoever.
Thanks yet again,
John <john@forkosh.com>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert animation (using postscript pages as frames)

Post by fmw42 »

My understanding about transparency and multipage files in PS/PDF is that the Ghostscript delegate can either handle one page file with transparency or multiple page files without transparency. That is set by the sDEVICE=pngalpha for the former or pnmraw for the latter in the delegates.xml file. But I am not an expert on this. So some one else may need to confirm that.
User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

Re: convert animation (using postscript pages as frames)

Post by forkosh »

Thanks again, Fred. As you probably guessed, I wasn't aware of that delegates.xml file, and (pretty much just for kicks) naively tried changing it to psrgb, which then ran convert for 22mins before I killed it (and switched delegates.xml back to original). But it certainly provides lots of flexibility (for people who actually know what they're doing). Thanks for that info -- when I finally figure out what I'm doing, I'm sure it'll come in very handy.

Meanwhile, I continued googling, and stumbled upon a 2004 (eight years ago) suggestion in this very forum to use
> -transparent "#FFFFFF"
which, along with -background transparent, had been among the first things I'd already tried before posting the question. But I nevertheless tried "#FFFFFF" again, and this time it worked (then I tried -background again, which continued to fail). Don't know what I could have originally done wrong (no errors/warnings from convert when I originally ran it). The new files (.gif and .ps) are at
> http://www.forkosh.com/decorative/decofweek-v2.gif
and
> http://www.forkosh.com/decorative/decofweek-v2.ps
File sizes are gif=5501543(v1)/361687(v2) and ps=397447(v1)/26968(v2). And this time convert took 31secs to run, which is way (12x) faster, but unfortunately still way too slow for me to enable that option for world online use.
Thanks again,
John <john@forkosh.com>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert animation (using postscript pages as frames)

Post by fmw42 »

-background is a setting and does nothing by itself. It is used in conjunction with other operators, such as -extent.

-transparent is the operator that actually changes some color to transparent
User avatar
forkosh
Posts: 6
Joined: 2012-08-05T01:45:00-07:00
Authentication code: 67789

Re: convert animation (using postscript pages as frames)

Post by forkosh »

Right. Thanks. I guess rtmf="reading [the manual] is fundamental". It also exactly explains my -transparent error: I'd tried -transparent-color "#FFFFFF", not -transparent, but forgot that until investigating your preceding remark. Sorry about that. Trying to fit too many little pieces together getting this toy working, and not really understanding any of them well.
Post Reply