# DALLE 2 - Transparent background and load image

**URL:** <https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973>\
**Category:** Beginners\
**Created:** [July 15, 2022, 4:21pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973 "2022-07-15T16:21:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scaprendering](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@Scaprendering](https://discourse.processing.org/u/Scaprendering)\
**Post date:** [July 15, 2022, 4:21pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973/1 "2022-07-15T16:21:43Z")

</div>

Hi brains !  
I’ll be honest, first day into processing today.  
I’ve done what I needed, basically crop and reposition images but I still have an issue about how to set the gray background to transparent.

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/7/07cb3022f9b6de861ac165a1156a810c8711e40f.png)

Here’s the code:

```auto

PImage img;
void setup() {
  size(4096,4096);
  noLoop();  
  int run = 0;
  int abscenterX = (width/2)-512;
  int abscenterY = (height/2)-512;
  imagePoss(abscenterX,abscenterY,run);
  run++;
  imagePoss(abscenterX+768,abscenterY-768,run);
  exit();
}
  
void imagePoss(int centerX,int centerY,int run)
{
  int sides = 5;
  int posX = 0;
  int posY = 0;
  int cropX = 0;
  int cropY = 0;
  for (int i = 0; i<sides; i++)
  {
    if (i%5 == 0)
    {  
      posX = centerX;
      posY = centerY;
    }
    if (i%5 == 1)
    {  
       posX = centerX;
       posY = centerY-768;
    }
    if (i%5 == 2)
    {
       posX = centerX+768;
       posY = centerY;
    }
    if (i%5 == 3)
    {
       posX = centerX;
       posY = centerY+768;
    }
     if (i%5 == 4)
    {
       posX = centerX-768;
       posY = centerY;
    }
    cropX = posX;
    cropY = posY;
    img = loadImage((run*sides)+i + ".png"); // Load the image into the program  
    image(img, posX, posY, 1024, 1024);
    PImage CropImage = get(cropX,cropY,1024,1024);
    CropImage.save(run+"_"+i+"_Crop.png");
    save("out.png");
  } 
}

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 15, 2022, 6:48pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973/2 "2022-07-15T18:48:28Z")

</div>

Hi @Scaprendering,

The canvas [background](https://processing.org/reference/background_.html) in processing is always opaque.  
If you want to save your images with transparency you need to go via [PGraphics object](https://processing.org/reference/PGraphics.html)

Also check [this](https://discourse.processing.org/t/making-a-transparent-background-and-exporting-to-png/37073/3).

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Scaprendering](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@Scaprendering](https://discourse.processing.org/u/Scaprendering)\
**Post date:** [July 15, 2022, 7:27pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973/3 "2022-07-15T19:27:37Z")

</div>

Thanks for the reply.  
I’ve found the same answer around the forum but I have no idea about how to implement that in my script.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 15, 2022, 8:14pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973/4 "2022-07-15T20:14:08Z")

</div>

Hi @Scaprendering,

Unfortunately I can’t test as I’m not at my box … but s.th. like this should help…

Cheers  
— mnse

```auto
PGraphics pg;
PImage img;

void setup() {
  size(4096,4096, P2D);
  noLoop();  
  pg = createGraphics(width, height, P2D);
  pg.beginDraw();
  pg.clear();
  int run = 0;
  int abscenterX = (width/2)-512;
  int abscenterY = (height/2)-512;
  imagePoss(abscenterX,abscenterY,run);
  run++;
  imagePoss(abscenterX+768,abscenterY-768,run);
  pg.endDraw();
  exit();
}
  
void imagePoss(int centerX,int centerY,int run)
{
  int sides = 5;
  int posX = 0;
  int posY = 0;
  int cropX = 0;
  int cropY = 0;
  for (int i = 0; i<sides; i++)
  {
    if (i%5 == 0)
    {  
      posX = centerX;
      posY = centerY;
    }
    if (i%5 == 1)
    {  
       posX = centerX;
       posY = centerY-768;
    }
    if (i%5 == 2)
    {
       posX = centerX+768;
       posY = centerY;
    }
    if (i%5 == 3)
    {
       posX = centerX;
       posY = centerY+768;
    }
     if (i%5 == 4)
    {
       posX = centerX-768;
       posY = centerY;
    }
    cropX = posX;
    cropY = posY;
    img = loadImage((run*sides)+i + ".png"); // Load the image into the program  
    pg.image(img, posX, posY, 1024, 1024);
    PImage CropImage = pg.get(cropX,cropY,1024,1024);
    CropImage.save(run+"_"+i+"_Crop.png");
  } 
  pg.save("out" + run + ".png");
}

```

Edit: changed back on get to PImage

---

<div class="post-metadata">

**Author:** ![Scaprendering](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@Scaprendering](https://discourse.processing.org/u/Scaprendering)\
**Post date:** [July 15, 2022, 9:03pm UTC](https://discourse.processing.org/t/dalle-2-transparent-background-and-load-image/37973/5 "2022-07-15T21:03:04Z")

</div>

Oh thanks for that !  
I understood a little better how this work thanks to your example but unfortunately I still get an error.

```auto
PGraphics CropImage = get(cropX,cropY,1024,1024);

```

“cannot convert from PImage to PGraphics”
