04-23-2019, 09:10 AM
Hi Ofnots,
Thanks for your help but I feel I am far away from getting this done without your coding help.
I am unable to translate all what is obvious for you pythonwise :-)
> I cannot find simple ways to export in png the file
> for some reason the script does not appear in the console
Could you please correct this code, knowing that the purpose is to deal with 400 photos and I would like their name to be the same in another file.
PS: my business is very small so I need to use to the max GNU solutions and their generous community;
Thanks again,
Chris
Thanks for your help but I feel I am far away from getting this done without your coding help.
I am unable to translate all what is obvious for you pythonwise :-)
> I cannot find simple ways to export in png the file
> for some reason the script does not appear in the console
Could you please correct this code, knowing that the purpose is to deal with 400 photos and I would like their name to be the same in another file.
PS: my business is very small so I need to use to the max GNU solutions and their generous community;
Thanks again,
Chris
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Erase a complex and non even background
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import os,sys,math,time
from gimpfu import *
def eraseBackground2(image,layer):
image.undo_group_start()
gimp.context_push()
try:
# 1. Duplicate the layer
DuplicateLayer = pdb.gimp_layer_copy(layer, add_alpha)
# 1.1 increase contrast and tweak the brightness so that everything you want to remove is white.
pdb.gimp_brightness_contrast(drawable, 10, 110)
# 2. apply color-to-alpha and remove the white
pdb.plug_in_colortoalpha(image, drawable, 255)
# 3. alpha-select the result
gimp_select_item()
# 4. add a layer mask to the initial image, using the selection to initialize the mask
pdb.gimp_image_add_layer_mask(image, layer-1, mask)
# 5. delete the copy
pdb.gimp_layer_delete(DuplicateLayer)
# 6. save in png
???
gimp.context_pop()
image.undo_group_end()
### Registration
whoiam='\n'+os.path.abspath(sys.argv[0])
author='Chris'
copyrightYear='2019'
desc='Erase a complex and non even background'
moredesc='\nWand-select (roughly) the background before use'
register(
'ofn-erase-background',
desc+moredesc+whoiam,desc,
author,author,copyrightYear,
'Erase uneven background',
'RGB*',
[
(PF_IMAGE, 'image', 'Input image', None),
(PF_DRAWABLE, 'drawable', 'Input drawable', None),
],
[],
eraseUnevenBackground2,
menu='<Image>/Layer'
)
main()