Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing Alpha Channel?
#6
(07-26-2022, 08:14 PM)david Wrote:
Code:
from gimpfu import *

def python_c_c_r(image,layer):
pdb.gimp_image_undo_group_start(image)
pdb.gimp_context_push()

width   = image.width
height  = image.height
type    = RGB_IMAGE
opacity = 100
mode    = NORMAL_MODE

layerClean = pdb.gimp_layer_new_from_drawable(layer, image) # layer to be cleaned of alpha channel
pdb.gimp_image_insert_layer(image, layerClean, None, 0) # insert layer
pdb.gimp_image_set_component_visible(image, CHANNEL_ALPHA, FALSE) # make alpha channel non-visible
pdb.gimp_layer_flatten(layer) # remove alpha channel
pdb.gimp_image_remove_layer(image, layerClean)

pdb.gimp_context_pop()
pdb.gimp_image_undo_group_end(image)
pdb.gimp_displays_flush()

register(
"python_fu_c_c_r",
"c_c_r",
"c_c_r",
"David Marsden",
"David Marsden",
"July 2022",
"<Image>/Python-Fu/c_c_r...",             #Menu path
"RGB*, GRAY*, INDEXED*",
[],
[],
python_c_c_r)

main()

Here is the total code. The same as you have seen already, apart from the parameters of the original image.
The subsequent code would create a new layer, pixelated to the maximum dimensions of the image, colour inverted and changed to overlay mode.

Oh... It's for that thread, that's very nice from you, BTW that's a cool trick with the big pixel averaging the color cast [Image: thumbsup.png]

I'm not programmer, but if I may... I would take/compare the longest side of the image after taking the width and the height (on your code) to pixelate at the longest side+1 to sure sure to pixelate a big one pixel to the whole image whatever is portrait or paysage.
Maybe something like that? (don't forget, no programmer here, no python knowledge and so, please forgive syntax and error)
Code:
width   = image.width
height  = image.height
type    = RGB_IMAGE
opacity = 100
mode    = NORMAL_MODE

 if (width >= height) {
     pixelSize = width+1;
   }
   else {
            pixelSize = height+1;
           }
// pixelSize is to use on the pixelization filter to scale the size of the pixel on both sliders

Also, do you really need to "touch" the alpha channel?
If a picture has an alpha channel but is opaque (like this photo on your first post), the pixelisation will work just fine.
If a picture has an alpha channel with some transparencies parts, removing the alpha channel will fill the transparency with the active BG color, thus if the active BG color was set to something exotic(or not), when the pixel will average the color cast, it will take in count the BG fill of the transparency as well, thus the averaging will be off, no?

Just a thought Smile
Reply


Messages In This Thread
Removing Alpha Channel? - by david - 07-26-2022, 02:27 PM
RE: Removing Alpha Channel? - by Ofnuts - 07-26-2022, 04:11 PM
RE: Removing Alpha Channel? - by david - 07-26-2022, 06:05 PM
RE: Removing Alpha Channel? - by Ofnuts - 07-26-2022, 07:34 PM
RE: Removing Alpha Channel? - by david - 07-26-2022, 08:14 PM
RE: Removing Alpha Channel? - by PixLab - 07-27-2022, 01:58 AM
RE: Removing Alpha Channel? - by david - 07-27-2022, 07:38 AM
RE: Removing Alpha Channel? - by rich2005 - 07-27-2022, 07:51 AM
RE: Removing Alpha Channel? - by david - 07-27-2022, 11:54 AM
RE: Removing Alpha Channel? - by Ofnuts - 07-27-2022, 05:33 PM
RE: Removing Alpha Channel? - by david - 07-28-2022, 09:34 AM
RE: Removing Alpha Channel? - by Ofnuts - 07-28-2022, 12:08 PM
RE: Removing Alpha Channel? - by david - 07-28-2022, 03:56 PM

Forum Jump: