Sun Mar 14, 2021 12:55 pm
Sun Mar 14, 2021 1:40 pm
Sun Mar 14, 2021 4:47 pm
leftyleo wrote:not sure why you need transparent border but this is what i did : ...
Sun Mar 14, 2021 7:13 pm
pinksy wrote:Hi. First time post, and gimp python newbie here, so apologies if this is obvious. I'm trying to emulate what I can do in the UI:
1. Create a new image, say 1000px wide, 500px high, transparent fill.
2. Open as layers "file1.png", which is 800px wide, 500px high - this leaves 100px of transparecy either side of the layer, which is what I want
3. Export as "file2.png" - gives me a 1000px by 500px PNG, with the 800px image in the middle, and 100px transparency on either side - perfect.
Here's what I have:
img=pdb.gimp_image_new(1000, 500, 0)
lyr=pdb.gimp_file_load_layer(img,'C:\temp/file1.png')
pdb.gimp_image_insert_layer(img, lyr, None, 0)
# here's where I'm lost... how do I save as png with the transparent border? The following saves just as 800px wide, and loses the 100px transparency on either side...
drw=pdb.gimp_image_active_drawable(img)
pdb.file_png_save2(img,drw,'C:\temp/file2.png', 'C:\temp/file2.png',0,9,0,0,0,1,1,1,1)
Any help gratefully received!
pdb.gimp_layer_add_alpha(layer)
Mon Mar 15, 2021 3:41 am
Pocholo wrote:Before you saved it, did you add an alpha to the layer:
- Code:
pdb.gimp_layer_add_alpha(layer)
Otherwise, the image will have a background color and will not keep the Transparency..
img=pdb.gimp_image_new(1000, 500, 0)
lyr=pdb.gimp_file_load_layer(img,'C:\temp/file1.png')
pdb.gimp_image_insert_layer(img, lyr, None, 0)
pdb.gimp_layer_add_alpha(lyr)
drw=pdb.gimp_image_active_drawable(img)
pdb.file_png_save2(img,drw,'C:\temp/file2.png', 'C:\temp/file2.png',0,9,0,0,0,1,1,1,1)
Mon Mar 15, 2021 9:45 am
pdb.gimp_drawable_fill(lyr, FILL_TRANSPARENT)
Mon Mar 15, 2021 6:43 pm
pinksy wrote:Pocholo wrote:Before you saved it, did you add an alpha to the layer:
- Code:
pdb.gimp_layer_add_alpha(layer)
Otherwise, the image will have a background color and will not keep the Transparency..
Hi @Pocholo. Ok, I tried that:
- Code:
img=pdb.gimp_image_new(1000, 500, 0)
lyr=pdb.gimp_file_load_layer(img,'C:\temp/file1.png')
pdb.gimp_image_insert_layer(img, lyr, None, 0)
pdb.gimp_layer_add_alpha(lyr)
drw=pdb.gimp_image_active_drawable(img)
pdb.file_png_save2(img,drw,'C:\temp/file2.png', 'C:\temp/file2.png',0,9,0,0,0,1,1,1,1)
...but it's still coming out cropped to the width of the inserted layer (800px) rather than the width of the overall image (1000px).
Is it something to do with merging? Or something I've got wrong with pdb.file_png_save2?
Thanks again for any help
Wed Mar 17, 2021 8:37 pm