# Save transparent image from Geomerative

**URL:** <https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132>\
**Category:** Libraries\
**Created:** [October 7, 2022, 12:57pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132 "2022-10-07T12:57:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellocatfood](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hellocatfood/32/17092_2.png) [@hellocatfood](https://discourse.processing.org/u/hellocatfood)\
**Post date:** [October 7, 2022, 12:57pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/1 "2022-10-07T12:57:05Z")

</div>

I have geomerative installed to modify an svg. I want to save an image with a transparent background whenever I left-click. However, using the code below, whenever I left click it only saves an image of the unmodified svg with a transparent background.

```auto
import geomerative.*;

RShape grp;
PGraphics img;

int first = 0;

void setup(){
  size(600, 600);
  
  RG.init(this);
  
  background(#2D4D83);
  
  img = createGraphics(width, height);
    
  grp = RG.loadShape("bot1.svg");
  grp = RG.centerIn(grp, g);
  
}

void draw(){
  img.beginDraw();
  img.translate(width/2, height/2);
  
  translate(width/2, height/2);
  
  float t = map(mouseX, 0, width, 0, 1);
  RShape[] splittedGroups = grp.splitPaths(t);
  
  RG.shape(splittedGroups[first]);
  grp.draw(img);
  img.endDraw();
}

void mousePressed(){
  first = (first + 1) % 2;
  img.save("image_" + millis() + ".png");
}

```

Not sure how I can make the `draw` command recognise the modified svg image.

---

<div class="post-metadata">

**Author:** ![matheplica](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matheplica/32/21035_2.png) [@matheplica](https://discourse.processing.org/u/matheplica)\
**Post date:** [October 7, 2022, 3:35pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/2 "2022-10-07T15:35:03Z")

</div>

Impossible to transform a RShape in PShape, so I found this alternative :

```auto
import geomerative.*;
RShape grp;
PGraphics img;
int first = 0;
PImage buf;
void setup() {
  size(600, 600);
  RG.init(this);
  background(#2D4D83);
  img = createGraphics(width, height);
  buf = createImage(width, height, RGB);
  grp = RG.loadShape("tiger.svg");
  grp = RG.centerIn(grp, g);
}
void draw() {
  img.beginDraw();
  img.translate(width/2, height/2);
  translate(width/2, height/2);
  float t = map(mouseX, 0, width, 0, 1);
  RShape[] splittedGroups = grp.splitPaths(t);
  RG.shape(splittedGroups[first]);
  grp.draw(img);
  img.endDraw();
  loadPixels();
  for (int i = 0; i < img.pixels.length; i++) {
    buf.pixels[i] = pixels[i];
  }
  updatePixels();
}
void mousePressed() {
  first = (first + 1) % 2;
  buf.save("image_" + millis() + ".png");
}

```

---

<div class="post-metadata">

**Author:** ![hellocatfood](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hellocatfood/32/17092_2.png) [@hellocatfood](https://discourse.processing.org/u/hellocatfood)\
**Post date:** [October 7, 2022, 4:10pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/3 "2022-10-07T16:10:37Z")

</div>

Thanks! This helps with save an image but not with saving a _transparent_ image. Any thoughts on how to save a transparent image?

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [October 7, 2022, 5:14pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/4 "2022-10-07T17:14:18Z")

</div>

> [@matheplica](#):
>
> `background(#2D4D83);`

You might try commenting out the background line to see if that makes a difference.  
Not sure if this is THE solution, but it is where I would start.  
🤓

---

<div class="post-metadata">

**Author:** ![hellocatfood](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hellocatfood/32/17092_2.png) [@hellocatfood](https://discourse.processing.org/u/hellocatfood)\
**Post date:** [October 7, 2022, 9:43pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/5 "2022-10-07T21:43:07Z")

</div>

> [@debxyz](#):
>
> You might try commenting out the background line to see if that makes a difference.  
> Not sure if this is THE solution, but it is where I would start.

Doesn’t work sadly. It just saves an image with the default light grey background (and with animation frames overlaid as the background isn’t redrawn)

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [October 7, 2022, 11:51pm UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/6 "2022-10-07T23:51:50Z")

</div>

This is an interesting thread which may be of help:

> [@Transparency in save() function](https://discourse.processing.org/t/transparency-in-save-function/25699):
>
> So I made this code where you can draw and create an image. This works just fine but is it possible to get an image with a transparant background? Is there like a function to remove everything with RGB code white in a certain area? Code: float oldX; float oldY; PImage test; void setup(){ fullScreen(); background(255); rect(40, 150, 200 ,100); test = loadImage("test.jpg"); } void draw(){ if(mousePressed){ line(mouseX, mouseY, oldX, oldY); } oldX = mouseX; oldY = mouseY; if(key…

---

<div class="post-metadata">

**Author:** ![hellocatfood](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hellocatfood/32/17092_2.png) [@hellocatfood](https://discourse.processing.org/u/hellocatfood)\
**Post date:** [October 8, 2022, 9:54am UTC](https://discourse.processing.org/t/save-transparent-image-from-geomerative/39132/7 "2022-10-08T09:54:35Z")

</div>

> [@debxyz](#):
>
> This is an interesting thread which may be of help:

Thanks but it doesn’t help either. As @matheplica pointed out it’s not possible to convert an RShape into a PShape (which the method you posted uses).
