choose starting frame (different than frame 0) for a GIF

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
svarturvalko
Posts: 2
Joined: 2018-08-25T00:15:48-07:00
Authentication code: 1152

choose starting frame (different than frame 0) for a GIF

Post by svarturvalko »

I'm using ImageMagick-7.0.6-Q16 on windows 10 via command line

I currently use a bat file I created to convert PNG sequences into GIFs while resizing and adding a text watermark in the process. It works fine, though in some cases I want to have the starting frame to be different (frame 25 for example) than frame 0, but still loop completely.

i.e. GIF start on 25f play through the end to frame 90 then continue 1 to 24 and loop.

my current solution has been batch renaming the files to choose the starting frame but then I have to alter all the provided frames and it's quite time consuming.

Ideally I'd like to have a way to set in the bat file the starting frame for the GIF and still loop through all provided images from the png sequence.

Is this possible?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: choose starting frame (different than frame 0) for a GIF

Post by snibgo »

I don't think GIF has any metadata that tells viewers to start displaying from some frame other than zero.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: choose starting frame (different than frame 0) for a GIF

Post by GeeMack »

svarturvalko wrote: 2018-08-25T00:33:05-07:00Ideally I'd like to have a way to set in the bat file the starting frame for the GIF and still loop through all provided images from the png sequence.
If you can set your desired starting frame number as a variable or an argument to your script, you can easily re-order the images when you read them into the "magick" command.

Code: Select all

set FRAME1=7

magick *.png ( -clone 0-%FRAME1% ) -delete 0-%FRAME1% +insert <other stuff...> output.gif
That would start the output animation with input frame "7", then continue to the end and back around to finish at frame "6". Remember the first frame is "0".
svarturvalko
Posts: 2
Joined: 2018-08-25T00:15:48-07:00
Authentication code: 1152

Re: choose starting frame (different than frame 0) for a GIF

Post by svarturvalko »

my knowledge on the command is very basic but currently am using this on my bat file.

convert +repage -fuzz 3.0%% -delay 3 -loop 0 *.png -layers OptimizePlus -layers OptimizeTransparency output.gif

Assuming my sequence si 90 frames and I wan it to start at frame 7 how would you adapt your code into mine?
sorry for maybe a simple answer, I tried in multiple ways to incorporate what you wrote but can't make it work. Also I always used convert, didn't know I can use "magick"
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: choose starting frame (different than frame 0) for a GIF

Post by GeeMack »

svarturvalko wrote: 2018-08-27T01:18:28-07:00Assuming my sequence si 90 frames and I wan it to start at frame 7 how would you adapt your code into mine?
The "( -clone 0-7 ) -delete 0-7 +insert" part of my example should be right after your command reads in the images...

Code: Select all

magick ... *.png ( -clone 0-7 ) -delete 0-7 +insert ... output.gif
After the command reads the list of images it adds a cloned copy of numbers 0 through 7 to the end of the list, then deletes images 0 through 7 from the beginning. (Since that is actually 8 images, it moves the last image back to the beginning with "+insert".) That re-arranges the input images to be something like "7, 8, 9, ... 0, 1, 2, 3, 4, 5, 6".

If your starting frame number will change from one run to another, you can set a variable ahead of the command and use it in the two places where I used the "7".
Also I always used convert, didn't know I can use "magick"
With IM7 you should be using "magick ...", "magick montage ...", "magick mogrify ...", etc.
Post Reply