Transparent Gifs

I know this is a bit of a silly request, but it would be great to have an option to export transparent GIFs. It would make things much easier for some animators, instead of using a green screen and having to resort to websites to do that part of the work. It would be like exporting a PNG, but the PNG moves!

Thanks for reading my request ;)

There’s a problem with creating transparent .GIF’s and that is that they’d be non standard. Whereas transparent .PNG’s are within the standard! Such files loaded into other graphics apps like Gimp might cause unexpected results.

Do you want Pencil2D to be able to export transparent animated .GIF’s? They’d be very useful in allowing layer consolidation.

Just some thoughts.

I can understand that, but… what if they do something like “green screen”? Some sites do it, but sometimes the results are awful and they end up tearing off a piece of the animation—something more like “green screen underneath your animation, export it and use chroma key”?

GIF’s were one of the first graphics formats developed. You can have a character on a say a white background where the transparency is set to 99%. But 100% transparency is not an option unless you write your own code to display the image. However 99% transparency does look in most circumstance as transparent.

Before GIF’s there were only character graphics, used on screen on micro computers and used in Teletext systems. These were developed on the basis that backgrounds were either paper, coloured white or on screen which by default was black.

GIF’s are still supported by many software suppliers, including Pencil2d because they are easy to use, are memory fairly efficient and easy to design.

There are animated PNG file formats, but these haven’t taken off because there are no industry standard formats agreed and there’s a lack of player support for each standard.

If you want to move an animation sequence from one project to another you can use a sequence of PNG files to achieve this result.

1 Like

Oh! I’d forgotten that Pencil 2D is somewhat “open source.” Would it be a good idea to create a setting called “import plugin” with a specific format for Pencil 2D? That way the community would have more freedom with their creations! For example, creating a dedicated panel for exporting transparent GIFs or other silly things.

Among Pencil2D’s developers I have probably done the most work on the current GIF and video exporter implementations, so let me take a minute to clarify some things here and address this oft-requested feature.

The GIF File Format

Animated GIFs support transparency, at least in the way a casual user would understand it. Each GIF defines a color palette of up to 256 colors*. These colors are represented with red, green, and blue color channels, which notably does not include an alpha channel for transparency. However, one position in the palette can be assigned to be fully transparent. That means GIFs can have fully opaque and fully transparent pixels, but nothing in between. The most noticeable consequence of this is jagged edges between transparent and opaque regions.

The other aspect of the GIF format which is relevant to this discussion is the disposal method. Each frame has a disposal method set which defines what happens to the frame after it has been displayed. In any sane video format, the frame is cleared as the next frame is displayed, but GIFs allow for some other options which are described in a bit more detail here. Usage of other disposal methods is actually quite common for reducing the file size of the image.

* Technically a new color palette can be specified for each frame, allowing for more than 256 colors at the cost of substantially larger file sizes. Pencil2D currently does not do this.

Pencil2D History Lesson

To create GIF files, Pencil2D relies upon the 3rd-party tool FFmpeg, which is packaged with each Pencil2D download. When the GIF export was initially implemented (or perhaps slightly before), FFmpeg was at version 2.x, which did not support transparency in GIFs at all. Transparent pixels would be automatically filled with white, so the option for transparency was disabled for GIF export. Transparency support was added in the FFmpeg 3.x series I believe.

A while later, after FFmpeg 4.0 had been released, Pencil2D’s GIF export was heavily modified to improve its speed and performance. As part of these changes, the FFmpeg version packaged with Pencil2D was updated to 4.1.1 (for most operating systems anyway). However, there was long-standing bug in FFmpeg where the first frame of the animation would have a disposal method not set to “replace”. Animations that were supposed to look like the image on the left were instead being exported by Pencil2D like the image on the right, with remnants of the first frame persisting:

Expected Animation FFmpeg Output (<4.3.2)
Working animation with transparency Broken animation with transparency

This result was completely unacceptable and there was no way to work around this bug. So I had no choice but to continue to leave transparency disabled for the GIF export.

Current State

The aforementioned bug was fixed and now transparent GIF export works well in FFmpeg, so why hasn’t it been enabled in Pencil2D? Well, the short answer is because it’s a lot of work to do it right.

In the last release, Pencil2D had effectively 8 different builds that managed by our small volunteer development team, including ones for platforms as far back as Windows XP and Mac OS X Snow Leopard. Many of these builds have their own ways of getting FFmpeg, some of which are complicated to change or don’t even have more up-to-date versions available. Upgrading can introduce breaking changes, so it must be done careful with testing. All of this is feasible, and far from the most complex request we’ve received. But it takes time and effort, which nobody has volunteer yet.

In the current stable release (v0.7.0), the “green screen” solution suggested above is already trivially possible by simply making a layer at the bottom of your animation and filling the first frame with a solid green color, but comes with obvious drawbacks for any animation with green in them, and can result in color bleed on the edges. There are also several formats which support exporting with transparency directly. Pencil2D can export to the APNG format which is not very popular, but is widely supported. The WebM export also has a transparency option and is a more popular format, however it is currently misconfigured in Pencil2D and may not work for you (I might fix this for v0.7.1). Even if it was working, support for playing back WebMs with transparency is not good in my experience. For transferring between programs, exporting to an image sequence is recommended; the PNG, TIFF, and WebP options all support transparency and are lossless.

Future Expectations

I do not have a crystal ball, but there is one truth that applies to all Pencil2D requests: they won’t get done until someone takes the initiative to do them. We are a fully open source (no need for double quotes!) and volunteer project, so that person could be anyone, even you! :index_pointing_at_the_viewer:

In practice however, these things almost always end up falling to one of our very small core development team, all of which have only so much personal time to dedicate to this project. If there is some good news, it is that we are dropping support for some of the oldest operating systems, and upgrading to our release process, both of which will make upgrading FFmpeg a bit easier than it has ever been before.

For me personally, I don’t plan on working on this until I am done with another rewrite of the video exporter, which has been in a half-finished state for a long time. Among other things, this rewrite will allow the exporter to adaptively present options based on the capabilities of the underlying tools, so we won’t have to upgrade FFmpeg for every build in order to start taking advantage of the latest features on some builds. That project however is a low priority for me with more pressing matters such as the upcoming v0.7.1 release which a few of us have been hard at work on.

Footnote

One thing brought up in this thread which I did not address is the suggestion of a plugin system. This is another thing that gets suggested occasionally, and I could dedicate another wall of text to this, but I won’t. The short answer is that it is a LOT of work, and there’s no indication that there’s any demand for this from developers. The program is already fully open for other people to contribute to or do their own thing with…and basically nobody does. This is a pretty common sight in open source projects.

Plugins are not a good solution for transparent GIF support in particular because this is a feature we want for all users. If someone wants to make a plugin for transparent GIF export, please just help us add transparent GIF support directly into Pencil2D.

If you’ve read through all of this, congratulations. I hope this has given you an understanding of why there isn’t support for exporting transparent GIFs in Pencil2D and what it will take to change that. If you skipped to the end of this hoping for a TLDR, you’re out of luck :wink:

3 Likes

Thank you scribblemaniac for answering our questions.

Can I ask a question, what is the reason for wanting .GIF animations with a transparent background?

I take what has been said by Scribblemaniac, based on experience and I examined their practical example animation.

From my experience there’s more than a single way of achieving a goal.

There are ways of converting a .MP4 file into a .GIF file have you investigated this as a possible solution? Have you considered this route?

Scribblemaniac also provides a selection of possible techniques to acheive a transparent background animation.

I can see advantages of animated .GIF’s have the advantage of being smaller file size.

Transparent-6

The animation above, I took the 2nd .GIF file and inputted into Gimp. I then deleted the contents of the first frame refered to as the background and then exported it as a .GIF file. Effectively what I’ve done, without intending to is I’ve set the 1st frame to be a transparent background only. Thus I’ve removed the problem.

The same process could be used on a .GIF produced using Pencil2D.

I’d like to echo StopMotionVector thanks to Scribblemaniac! Your explanation has greatly aided my understanding of animated .GIF files.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.