Gif camera

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt-get update
# Optional
sudo apt-get upgrade

# Used to control camera
sudo apt-get install python-picamera python3-picamera
# Used to convert jpg to gif
sudo apt-get install graphicsmagick

sudo apt-get install git-core
# This script is used in 'PIX-E Gif Camera' project
sudo git clone https://github.com/nickbrewer/gifcam.git

If we just want raspberry pi camera can take gif picture, we can just remove `GPIO` and `Twitter` module, no need led notification/ real time upload ro so.

1
2
3
4
5
6
7
8
# import module first
import picamera
from time import sleep
import time
import datetime
from os import system
import os
import random, string
1
2
3
4
# set options
um_frame = 8 # Number of frames in Gif
gif_delay = 15 # Frame delay [ms]
rebound = True # Create a video that loops start <=> end
1
2
3
4
5
6
# set camera parameters
camera = picamera.PiCamera()
camera.resolution = (540, 405)
camera.rotation = 90
#camera.brightness = 70
camera.image_effect = 'none'

Take jpg pictures

1
2
3
4
5
6
7
8
9
10
print('Gif Started')

### PREVENT DARK INIT IMAGE ###
camera.led = False
camera.start_preview()
sleep(1)
camera.led = True

for i in range(num_frame):
camera.capture('{0:04d}.jpg'.format(i))

If rebound is True then make picture loop

1
2
3
4
5
6
7
8
9
### PROCESSING GIF ###
if rebound == True: # make copy of images in reverse order
for i in range(num_frame - 1):
source = str(num_frame - i - 1) + ".jpg"
source = source.zfill(8) # pad with zeros
dest = str(num_frame + i) + ".jpg"
dest = dest.zfill(8) # pad with zeros
copyCommand = "cp " + source + " " + dest
os.system(copyCommand)

Convert picture to gif and cleanup

1
2
3
4
5
6
7
8
9
10
11
# Correction of time difference
now = datetime.datetime.now() + datetime.timedelta(hours=8)
filename = '/home/pi/gifcam/gifs' + now.strftime('%Y%m%d%H%M%S')
print('Processing')
# Convert command
graphicsmagick = "gm convert -delay " + str(gif_delay) + " " + "*.jpg " + filename + ".gif"
os.system(graphicsmagick)
os.system("rm ./*.jpg") # cleanup source images

print('Done')
print('System Ready')

http://shumeipai.nxez.com/2016/11/06/build-a-disposable-gif-camera.html
https://hackaday.io/project/16358-pix-e-gif-camera