Creating GIFs
Gifs (Graphics Interchange Format) are animated images that can be created via SkImage. Basically, you’ll add frames to a gif, and then save it.
Creating a gif
Section titled “Creating a gif”You first need to create a gif object. To be honest, that’s the most complex part as you’ll configure everything right now:
set {_gif} to new infinite gif manager with new image with size 100, 100 with delay 1 and store it in file "test.gif"That may look complicated, but it’s actually not. Let’s break it down:
new infinite gif managercreates a new gif manager. Using the infinite keyword will make the gif loop infinitely.with new image with size 100, 100creates and defines the image that will be used for the gif. In this case, it’s a 100x100 transparent image.with delay 1defines the delay between each frame. In this case, it’s 1 millisecond.and store it in file "test.gif"defines the file where the gif will be saved. In this case, it’stest.gifin the server’s root folder.
Adding frames
Section titled “Adding frames”Now that the gif is created, you can add frames to it. To do so, simply use the gif images properties:
# We create the imageset {_img} to new image with size 100, 100
# We make a random colorset {_r} to random integer between 0 and 255set {_g} to random integer between 0 and 255set {_b} to random integer between 0 and 255set {_color} to color from rgb {_r}, {_g}, {_b}
# We draw a rectangle on the imagedraw filled (new rectangle with width 100 and height 100 and color {_color}) on {_img} at 0, 0
# We add the image to the gifadd {_img} to images of {_gif}Closing the gif
Section titled “Closing the gif”Once you’re done adding frames, you’ll have to close the gif. It will save the gif to the file specified when you created the gif manager, and close any ongoing stream.
To do so, simply use the close expression:
close gif {_gif}Example
Section titled “Example”Let’s create a gif that will display a random color every second. It’ll contain 10 frames, and will be saved in the server’s root folder as test.gif.
# We create the gif managerset {_gif} to new infinite gif manager with new image with size 100, 100 with delay 1000 and store it in file "plugins/test.gif"
# We create 10 different imagesloop 10 times: set {_img} to new image with size 100, 100 set {_r} to random integer between 0 and 255 set {_g} to random integer between 0 and 255 set {_b} to random integer between 0 and 255 set {_color} to color from rgb {_r}, {_g}, {_b}
draw filled (new rectangle with width 100 and height 100 and color {_color}) on {_img} at 0, 0 add {_img} to images of {_gif}
# We close the gifclose gif {_gif}