Page 1 of 1
					
				IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T11:52:03-07:00
				by burt46
				Hi, 
I have a IMagick PHP code that i use from a cron job to generate GIF files from folders of images. The problem is that the gifs are around 3 - 10mb in size and take too long to download.
Is it possible to generate a gif but say every n image in a folder? I have seen this is possible to extract frames from a GIF but not to generate a GIF. 
I have tried various methods to reduce the GIF size and the sizes above are already optimised.
Grateful for any advice.
Many thanks
Burt
			 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:02:26-07:00
				by fmw42
				You would have to write a script loop to take only every other images from the folder to make your gif. You could for example save a list of every other file into a variable or as text file and read from that text file.
The IM frame command [X-Y] does not have a skip feature, as far as I know.
It is generally a good idea to identify your IM version and platform when asking questions.
			 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:10:09-07:00
				by burt46
				Thanks for the reply. I guess this is a separate feature to IM to generate the txt file? Perhaps a cron job can do this too.
Linux, IM version 6.6.3
			 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:10:40-07:00
				by fmw42
				Another idea would be to delete every other image in the command sequence. In command line, suppose you have 10 images in the folder, you could do
Code: Select all
convert -delay 50  *.jpg -delete 1,3,5,7,9 -loop 0 result.gif
IM 6.6.3 is ancient (about 350 versions old). I would suggest you upgrade if you can.
 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:22:18-07:00
				by burt46
				Thanks for the feedback. I thought about this but it would delete my master images that i need for other scripts.
I cant change the IM version as it is controlled by my hosting company
			 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:29:21-07:00
				by fmw42
				using -delete does not delete images from your folder, only from the in memory sequence loaded by *.jpg.
However, it would be better to load only the images you want.
Code: Select all
cd somedirectory
imgArr=(`ls`)
num=${#imgArr[*]}
list=""
for ((i=0; i<num; i=i+2)); do
list="$list ${imgArr[$i]}"
done
convert -delay 50 $list -loop 0 result.gif
 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T13:30:37-07:00
				by burt46
				Perfect. Many thanks for the help.
			 
			
					
				Re: IMagick to generate GIF and skip every n image
				Posted: 2017-02-21T15:04:29-07:00
				by fmw42
				If you just want JPG, then use