# PGraphics saving to GIF with transparent background

**URL:** <https://discourse.processing.org/t/pgraphics-saving-to-gif-with-transparent-background/42267>\
**Category:** Processing\
**Created:** [June 22, 2023, 11:07am UTC](https://discourse.processing.org/t/pgraphics-saving-to-gif-with-transparent-background/42267 "2023-06-22T11:07:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 22, 2023, 11:20am UTC](https://discourse.processing.org/t/pgraphics-saving-to-gif-with-transparent-background/42267/2 "2023-06-22T11:20:03Z")

</div>

Hello @hareti,

See these issues and workaround/fix:

- [Copying PGraphics to PImage using .get() or .copy() clears PGraphics object, if the renderer is P2D · Issue #681 · benfry/processing4 · GitHub](https://github.com/processing/processing4/issues/681)
- [Second beginDraw / endDraw call clears PGraphics object when created w/ P2D · Issue #641 · benfry/processing4 · GitHub](https://github.com/processing/processing4/issues/641) \< Above refers to this

From issue above:

```auto
  // ---- include to fix ----
  pg.beginDraw();
  pg.endDraw();
  // ------------------------

```

Your code saves the expected PNG files with the above added.

I have encountered this issue in the past:

> [@Very weird stuff going on with colors and transparency with the P2D renderer](https://discourse.processing.org/t/very-weird-stuff-going-on-with-colors-and-transparency-with-the-p2d-renderer/40924/9):
>
> Hello @PianoMastR64, When using PGraphics I have always had a setup frame first; I may have encountered this issue in the past and in the habit of doing this now. This will get around that first frame behavior. This code has the PG setup frame and will toggle between PGraphics renderers (P2D and JAVA2D): PGraphics pg; boolean toggle; void setup() { size(800, 800, P2D); if (toggle) { pg = createGraphics(width, height, JAVA2D); println("PG P2D"); println("Renderer: " …

`:)`

---

_[View the full topic](https://discourse.processing.org/t/pgraphics-saving-to-gif-with-transparent-background/42267)._
