Take me back!

PilAnimate Documentation


PilAnimate is a python library that renders video frame by frame, using PIL.

Documentations are up to date for version 0.4.1. A lot of the library is just a wrapper for PIL, so if you are having trouble it could be useful to reference those if you encounter any issues.

Why use PilAnimate?

I mostly made PilAnimate for my personal use, and I'm sure there's probably better ones out there, but I made PilAnimate to be fairly simple and easily extendable. It renders frame by frame, meaning that even the most complex tasks can be completed on old computers, albeit slowly.

Install

pip install pilanimate

Animation

Class

Creates layers

Parameters:

Returns: itself

Properties: layers, fps, mode, size

export

Function

Turns frames into video.

Parameters:

Returns: Nothing, creates filename+".avi" video

Layer

Class

Creates layer. A layer is essentially an array of images. When the video is exporting, the layers will be pasted on each other to create an array of frames (layer 0 is at the bottom).

Warning: Do not create this class yourself, making the Animation class will do it for you.

Parameters:

Returns: itself

Properties: size, img, layer, fps, frames, mode

createPoint

Function

Creates a point at coords

Parameters:

Returns: nothing

createLine

Function

Creates line, where each array [x,y] inside coords is a point, connected in order.

Parameters:

Returns: nothing

createArc

Function

Creates arc with starting and ending angles inside the bounding box.

Parameters:

Returns: nothing

createEllipse

Function

Creates ellipse inside bounding box

Parameters:

Returns: nothing

createPolygon

Function

Creates polygon

Parameters:

Returns: nothing

createRectangle

Function

Creates rectangle

Parameters:

Returns: nothing

createRoundedRectangle

Function

Creates a rounded rectangle

Parameters:

Returns: nothing

fillAll

Function

Fills entire layer with color

Parameters:

Returns: nothing

createText

Function

Creates text at coords to layer. Has a kinds of parameters that can be fiddled with, making it a really powerful function.

Parameters:

Returns: nothing

addImage

Function

Adds image to layer

Parameters:

Returns: nothing

addGif

Function

Adds a gif to the layer (this function also creates frames for you, for the number of frames long the gif is * times_to_repeat frames)

Parameters:

Returns: nothing, but appends frames

rotate

Function

Rotates layer

Parameters:

Returns: nothing

translate

Function

Move layer

Parameters:

Returns: nothing

changeOpacity

Function

Changes opacity (transparency) of the layer, of every non transparent pixel.

Parameters:

Returns: nothing

changeEntireOpacity

Function

Changes opacity of entire layer, including transparent pixels, so only use this for layers with no transparent parts

Parameters:

Returns: nothing

fadeIn

Function

Slowly fades in a layer, going from transparent to fully opaque.

Parameters:

Returns: nothing, but appends frames

fadeOut

Function

Slowly fades out a layer, going from fully opaque to fully transparent.

Parameters:

Returns: nothing, but appends frames

transform

Function

Transforms layer. This function is very complicated so and frankly I have no clue what most of thse are, so please refer to PIL Docs for more detail.

Parameters:

Returns: nothing

blur

Function

Blurs layer

Parameters: none

Returns: nothing

clear

Function

Clears area of layer, turning it transparent

Parameters:

clearAll

Function

Clears entire layer, turning it transparent

Parameters: none

Returns: nothing

saveFrame

Function

Adds the layer in its current state to the frames array

Parameters: none

Returns: nothing, but appends a frame

doNothing

Function

Adds frames without changing the layer

Parameters:

Returns: nothing

save

Function

Save current layer as a file

Parameters:

Returns: nothing

rise

Function

Make layer slowly rises

Parameters:

Returns: nothing, but appends frames

descend

Function

Make layer slowly descend

Parameters:

Returns: nothing, but appends frames

slide

Function

Makes the layer slide to the side

Parameters:

Returns: nothing, but appends frames

spin

Function

Makes the layer spin

Parameters:

Returns: nothing, but appends frames

Example

Here's a basic example that creates a sun rising from the sea:

from PilAnimate import Animation, ImageColor, Image
animation = Animation(3)
animation.layers[0].fillAll(fill="SkyBlue")
#sun layer
animation.layers[1].createEllipse(((700,650),(900,850)), fill="yellow")
#ocean layer
animation.layers[2].createRectangle(((0, 500),(1600,900)), fill="Blue", width=0)
animation.layers[0].doNothing(100)
animation.layers[2].doNothing(100)
animation.layers[1].rise(100, -501)
animation.export()

Extend

Example of an extension I made that makes backgrounds:

from PilAnimate import Layer
import math
class Background():
  #remember to add params
  def __init__(self, layer, background_image):
    self.background_image = background_image
    self.layer = layer
    self.layer.addImage(self.background_image.copy().crop((0,0,self.layer.size[0],self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1]))
  def pan_down(self, frames, all_the_way=True):
    #speed is pixels per frame
    #(background_image height-layer height)/speed
    #
    amount = (self.background_image.size[1]-self.layer.size[1])/frames
    amount = math.floor(amount)
    for i in range(frames-1):
      self.layer.addImage(self.background_image.copy().crop((0, i*amount, self.background_image.size[0], i*amount+self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1]))
      self.layer.saveFrame()
    if all_the_way:
      self.layer.addImage(self.background_image.copy().crop((0, (self.background_image.size[1]-self.layer.size[1]), self.background_image.size[0], (self.background_image.size[1]-self.layer.size[1])+self.layer.size[1])), coords=(0, 0, self.layer.size[0], self.layer.size[1]))
      self.layer.saveFrame()