Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scripts for comics trip
#3
This next script exports as png all .xcf files of the same folder as the current image in a /rendu/ folder. I use it to export all the pages of the comics Im working on. I made it with chatgpt, it's the first time I use it to program, and I'm impressed.
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# GIMP plugin to export all .xcf files of the folder in a /rendu/ folder
# (c) Jacques Duflos 2023
#
#   History:
#
#   v0.0: 2023-xx-xx: First published version

#   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
#   MERCHANTABILITY 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 random
import sys, os
from gimpfu import *
import gimpcolor


debug = False
def trace(s):
   if debug:
       print "**** "
       print s
       print "**** "
trace("export group test")

def export_groupe(image):
   # Chemin complet vers le fichier actif
   chemin_fichier = image.filename

   # Obtenir le chemin du dossier contenant le fichier
   dossier = os.path.dirname(chemin_fichier)

   # Chemin du dossier de rendu
   dossier_rendu = os.path.join(dossier, 'Rendu')
   try:
       os.makedirs(dossier_rendu)
   except OSError:
       pass

   # Obtenir la liste des fichiers dans le même dossier
   fichiers_dossier = os.listdir(dossier)

   # Filtrer les fichiers avec l'extension ".xcf"
   fichiers_xcf = [fichier for fichier in fichiers_dossier if fichier.endswith(".xcf")]

   # Exporter les fichiers .xcf vers le dossier de rendu
   for fichier in fichiers_xcf:
       chemin_complet = os.path.join(dossier, fichier)
       nom_fichier, _ = os.path.splitext(fichier)

       # Charger le fichier .xcf dans GIMP
       image_xcf = pdb.gimp_xcf_load(0, chemin_complet, chemin_complet)

       # Exporter le fichier dans le dossier de rendu
       chemin_rendu = os.path.join(dossier_rendu, nom_fichier + ".png")
       new_image = pdb.gimp_image_duplicate(image_xcf)
       layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE)
       pdb.gimp_file_save(new_image, layer, chemin_rendu, '?')
       pdb.gimp_image_delete(new_image)
       pdb.gimp_image_delete(image_xcf)

    
    
### Registrations
whoiam='\n'+os.path.abspath(sys.argv[0])

register(
   'export-groupe',
   'exporter tous les .xcf du dossier %s' % whoiam,
   'exporter tous les .xcf du dossier',
   'Jacques Duflos','Jacques Duflos','2023',
   'exporter tous les .xcf du dossier...',
   '*',
   [
       (PF_IMAGE,  'image',            'Image', None),
   ],
   [],
   export_groupe,
   menu='<Image>/Layer'
)

main()
Reply


Messages In This Thread
scripts for comics trip - by jacques_duflos - 05-11-2023, 08:11 PM
RE: scripts for comics trip - by Ofnuts - 05-11-2023, 09:25 PM
RE: scripts for comics trip - by jacques_duflos - 06-10-2023, 12:38 AM
RE: scripts for comics trip - by Ofnuts - 06-10-2023, 07:23 AM
RE: scripts for comics trip - by jacques_duflos - 06-10-2023, 08:27 PM
RE: scripts for comics trip - by Ofnuts - 06-10-2023, 09:13 PM

Forum Jump: