Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp, Python versions, and flatpak
#5
Thanks for all your help with this.  I have it working nicely now.  The full setup is I have a script that watches for changes in a mailbox, downloads incoming files and strips off any attachments.  When it has found a new image it calls the batch file to process this image - basically resize it and put it into a mask (premade templat.xcf) to print out a badge.  The xcf file is then saved so that a user can open it, slide the image around in the mask, resize if necessary, and print.  

Just so that others have some more code samples for gimp 3.0 I'll upload the key section here and hope this helps someone else.  Thanks again

Code:
for fname in glob.glob(os.path.join(imagepath, '*.*')):
           Gimp.message('get the template file')
           tfile = Gio.File.new_for_path(os.path.join(templatepath, 'template.xcf'))
           Gimp.message('build an image from the file')
           timage = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, tfile)
           Gimp.message('get the group layer of the template')
           tgroup = timage.get_layers()[0]
           Gimp.message(fname)
           f = Gio.File.new_for_path(fname)
           Gimp.message('build a work image')
           work_im = Gimp.file_load(Gimp.RunMode.NONINTERACTIVE, f)
           h = Gimp.Image.get_height(work_im)
           Gimp.message('here')
           w = Gimp.Image.get_width(work_im)
           if h < 600 or w < 600:
               pass
           else:
               height = 600
               width = w / (h / 600)
           Gimp.Image.scale(work_im, int(width), int(height))
           Gimp.message('get background layer from the work image')
           layer = work_im.get_layers()[0]
           Gimp.message('create a layer for the template')
           # copy to template
           tlayer = Gimp.Layer.new_from_drawable(layer, timage)
           Gimp.message('set to intersection')
           Gimp.Layer.set_composite_mode(tlayer, Gimp.LayerCompositeMode.INTERSECTION)
           Gimp.message('rename the layer')
           fname, file_extension = os.path.splitext(os.path.basename(fname))
           Gimp.message(fname)
           Gimp.Item.set_name(tlayer, fname)
           # Gimp.Item.set_name(timage, fname)
           Gimp.message('add the intersect layer to the group')
           Gimp.Image.insert_layer(timage, tlayer, timage.get_layers()[0], 1)
           # should be view circle, image, inner circle
           #Gimp.Display.new(timage) - this is now called interactively so there is no display
           Gimp.Image.delete(work_im)
           Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, timage,
                          Gio.File.new_for_path(os.path.join(imagepath, 'waiting/', fname + '.xcf')))
Reply


Messages In This Thread
RE: Gimp, Python versions, and flatpak - by chrispanda - 01-05-2025, 11:26 PM

Forum Jump: