Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 22/05/2010, à 18:14

LaurentRoland

Plugin Python avec Gimp2.6

Bonjour à tous smile
J'ai trouvé un script python pour Gimp: ResizeMultiple sur le site
http://remyb.roller.free.fr/wikini/wakka.php?wiki=ResizeMultiple
Ce script dimensionne des photos selon les critères de PhpWebGallery. Maintenant appelé Piwigo.
Voici le script:

#!/usr/bin/python

import os, stat, mimetypes, shutil
from gimpfu import *
from Tkinter import *
import tkMessageBox
import sys

def resize(pInit, bAdd, bOri, iTN, iStd):
	bDebug = True
	img_types = ('image/jpeg', 'image/png') 	
	for root, dirs, files in os.walk(pInit, topdown=False):
		# les anciennes vignettes sont supprimes
		if root.find("thumbnail") > -1 :
			if not(bAdd) :
				# si on est pas en ajout, on supprime les vignettes
				for fImg in files:
					pImg=os.path.join(root, fImg)
					mmt = mimetypes.guess_type(pImg)
					if mmt[0] in img_types :
						os.remove(pImg)
		
		elif root.find("pwg_high") > -1 :
			# haute resolution, seul les ajout complet sont traite
			for fImg in files:
				pImgPH=os.path.join(root, fImg)
				mmt = mimetypes.guess_type(pImgPH)
				if mmt[0] in img_types :
					pImg=os.path.join(root,"..", fImg)
					pImgTN=os.path.join(root,"..","thumbnail", "TN-"+fImg)
					if not(os.access(pImg, os.F_OK)) :
							iImg = pdb.gimp_file_load(pImgPH, pImgPH)
							resize_img(iImg, iStd, pImg)
							resize_img(iImg, iTN, pImgTN)
							pdb.gimp_image_delete(iImg)

		else :
			# Test et creation eventuelles du repertoire des vignettes
			pTN = os.path.join(root,"thumbnail")
			if not(os.access(pTN, os.F_OK)) :
				os.mkdir(pTN, stat.S_IRWXU)
			if not(os.access(pTN, os.W_OK)) :
				os.chmod(pTN, stat.S_IRWXU)

			# Test et creation eventuelles du repertoire des originaux
			pPH = os.path.join(root,"pwg_high")
			if os.access(pPH, os.W_OK) :
				bPH = True
			elif bOri and not(os.access(pPH, os.F_OK)) :
				os.mkdir(pPH, stat.S_IRWXU)
				bPH = True
			else :
				bPH = False

			for fImg in files:
				pImg=os.path.join(root, fImg)
				mmt = mimetypes.guess_type(pImg)
				if mmt[0] in img_types :
					pImgPH=os.path.join(pPH, fImg)
					if os.access(pImgPH, os.F_OK) :
						pOri=pImgPH
					elif bPH :
						shutil.copy(pImg, pImgPH)
						os.remove(pImg)
						pOri=pImgPH
					else :
						pOri=pImg
					
					pImgTN=os.path.join(pTN,"TN-" + fImg)
					
					# en ajout test de la presence de la photo
					if bAdd :
						if not(os.access(pImg, os.F_OK) or os.access(pImgTN, os.F_OK)) :
							iImg = pdb.gimp_file_load(pOri, pOri)
							resize_img(iImg, iStd, pImg)
							resize_img(iImg, iTN, pImgTN)
							pdb.gimp_image_delete(iImg)
						elif not(os.access(pImg, os.F_OK)) :
							iImg = pdb.gimp_file_load(pOri, pOri)
							resize_img(iImg, iStd, pImg)
							pdb.gimp_image_delete(iImg)
						elif not(os.access(pImgTN, os.F_OK)) :
							iImg = pdb.gimp_file_load(pImg, pImg)
							resize_img(iImg, iTN, pImgTN)
							pdb.gimp_image_delete(iImg)
					else :
						pImgTmp=os.path.join(root,"tmp-"+fImg)
						if pOri==pImg :
							shutil.copy(pImg, pImgTmp)
						# on charge l'image, et on la standardise
						iImg = pdb.gimp_file_load(pOri, pImgTmp)
						resize_img(iImg, iStd, pImg)
						resize_img(iImg, iTN, pImgTN)
						pdb.gimp_image_delete(iImg)
						if pOri==pImg :
							os.remove(pImgTmp)


def resize_img(iImg, iScale, pImg) :
	iW=iImg.width				
	iH=iImg.height
	if iW>iH and iW>iScale :
		iH = iScale * iH / iW
		iW = iScale
		iImg.scale(iW, iH)
	elif  iH>iScale :
		iW = iScale * iW / iH
		iH = iScale
		iImg.scale(iW, iH)
	pdb.gimp_file_save(iImg, iImg.active_layer, pImg, pImg)	
			

register(
	"python_fu_myvignette",
	"Redimensionne les images d'un repertoire",
	"Enregistre les images d'un dossier",
	"Remy BERNARD",
	"Remy BERNARD",
	"2006",
	#	"<Toolbox>/Xtns/Python-Fu/Utilitaires/PhpWebGallery",
	"<Toolbox>/Xtns/PhpWebGallery",
	"",
	[
	(PF_FILE, "pInit", "Dossier initial","~/Desktop/essai"),
	(PF_BOOL, "bAdd", "Ajout seulement ?",1),
	(PF_BOOL, "bOri", "Originaux a deplacer vers pwg_high ?",1),
	(PF_INT, "iTN", "Taille des vignettes (pixel)",64),
	(PF_INT, "iStd", "Taille standard (pixel)",640),
	],
	[],
	resize)

main()

Je n'arrive pas a le faire fonctionné sous Gimp 2.6, je pense que c'est parce-qu'il a été créer pour une utilisation sous Gimp2.2.
Est-ce que l'un de vous saurait le modifier pour une utilisation sous Gimp 2.6 ? neutral:|


ubuntu 9.10, Acer Aspire 9420, dual screen avec écran Cibox 1280x1024

Hors ligne

#2 Le 23/05/2010, à 17:11

LaurentRoland

Re : Plugin Python avec Gimp2.6

Personne n'a d'idée ... hmm


ubuntu 9.10, Acer Aspire 9420, dual screen avec écran Cibox 1280x1024

Hors ligne

#3 Le 27/05/2010, à 18:52

LaurentRoland

Re : Plugin Python avec Gimp2.6

Personne n'a de réponse ...???:o
Pourtant c'est un script qui pourrait servir à beaucoup de monde!
Il est capable de redimensionner une image en deux formats différents, un pour la vignette et un pour l'affichage de l'image au format normal.
De plus avec Piwigo il y a une option pour l'affichage en haute résolution. Une option prévu avec se script.


ubuntu 9.10, Acer Aspire 9420, dual screen avec écran Cibox 1280x1024

Hors ligne

#4 Le 07/09/2011, à 22:13

remyb

Re : Plugin Python avec Gimp2.6

Mieux vaut tard que jamais...
J'ai fait quelques corrections dans mon script :

#!/usr/bin/python

import os, stat, mimetypes, shutil
from gimpfu import *
import sys

def resize(pInit, bAdd, bOri, iTN, iStd):
    img_types = ('image/jpeg', 'image/png') 
    if os.path.isfile(pInit) :
        pInit = os.path.dirname(pInit)
    for root, dirs, files in os.walk(pInit, topdown=False):
        # les anciennes vignettes sont supprimes
        if root.find("thumbnail") > -1 :
            if not(bAdd) :
                # si on est pas en ajout, on supprime les vignettes
                for fImg in files:
                    pImg=os.path.join(root, fImg)
                    mmt = mimetypes.guess_type(pImg)
                    if mmt[0] in img_types :
                        os.remove(pImg)
        
        elif root.find("pwg_high") > -1 :
            # haute resolution, seul les ajout complet sont traite
            for fImg in files:
                pImgPH=os.path.join(root, fImg)
                mmt = mimetypes.guess_type(pImgPH)
                if mmt[0] in img_types :
                    pImg=os.path.join(root,"..", fImg)
                    pImgTN=os.path.join(root,"..","thumbnail", "TN-"+fImg)
                    if not(os.access(pImg, os.F_OK)) :
                            iImg = pdb.gimp_file_load(pImgPH, pImgPH)
                            resize_img(iImg, iStd, pImg)
                            resize_img(iImg, iTN, pImgTN)
                            pdb.gimp_image_delete(iImg)

        else :
            # Test et creation eventuelles du repertoire des vignettes
            pTN = os.path.join(root,"thumbnail")
            if not(os.access(pTN, os.F_OK)) :
                os.mkdir(pTN, stat.S_IRWXU)
            if not(os.access(pTN, os.W_OK)) :
                os.chmod(pTN, stat.S_IRWXU)

            # Test et creation eventuelles du repertoire des originaux
            pPH = os.path.join(root,"pwg_high")
            if os.access(pPH, os.W_OK) :
                bPH = True
            elif bOri and not(os.access(pPH, os.F_OK)) :
                os.mkdir(pPH, stat.S_IRWXU)
                bPH = True
            else :
                bPH = False

            for fImg in files:
                pImg=os.path.join(root, fImg)
                mmt = mimetypes.guess_type(pImg)
                if mmt[0] in img_types :
                    pImgPH=os.path.join(pPH, fImg)
                    if os.access(pImgPH, os.F_OK) :
                        pOri=pImgPH
                    elif bPH :
                        shutil.copy(pImg, pImgPH)
                        os.remove(pImg)
                        pOri=pImgPH
                    else :
                        pOri=pImg
                    
                    pImgTN=os.path.join(pTN,"TN-" + fImg)
                    
                    # en ajout test de la presence de la photo
                    if bAdd :
                        if not(os.access(pImg, os.F_OK) or os.access(pImgTN, os.F_OK)) :
                            iImg = pdb.gimp_file_load(pOri, pOri)
                            resize_img(iImg, iStd, pImg)
                            resize_img(iImg, iTN, pImgTN)
                            pdb.gimp_image_delete(iImg)
                        elif not(os.access(pImg, os.F_OK)) :
                            iImg = pdb.gimp_file_load(pOri, pOri)
                            resize_img(iImg, iStd, pImg)
                            pdb.gimp_image_delete(iImg)
                        elif not(os.access(pImgTN, os.F_OK)) :
                            iImg = pdb.gimp_file_load(pImg, pImg)
                            resize_img(iImg, iTN, pImgTN)
                            pdb.gimp_image_delete(iImg)
                    else :
                        pImgTmp=os.path.join(root,"tmp-"+fImg)
                        if pOri==pImg :
                            shutil.copy(pImg, pImgTmp)
                        # on charge l'image, et on la standardise
                        iImg = pdb.gimp_file_load(pOri, pImgTmp)
                        resize_img(iImg, iStd, pImg)
                        resize_img(iImg, iTN, pImgTN)
                        pdb.gimp_image_delete(iImg)
                        if pOri==pImg :
                            os.remove(pImgTmp)


def resize_img(iImg, iScale, pImg) :
    iW=iImg.width                
    iH=iImg.height
    if iW>iH and iW>iScale :
        iH = iScale * iH / iW
        iW = iScale
        iImg.scale(iW, iH)
    elif  iH>iScale :
        iW = iScale * iW / iH
        iH = iScale
        iImg.scale(iW, iH)
    pdb.gimp_file_save(iImg, iImg.active_layer, pImg, pImg)    
            

register(
    "python_fu_myvignette",
    "Redimensionne les images d'un repertoire par exemple pour Piwigo",
    "Redimensionne les images d'un repertoire par exemple pour Piwigo",
    "Remy BERNARD",
    "Remy BERNARD",
    "2011",
    #    "<Toolbox>/Xtns/Python-Fu/Utilitaires/PhpWebGallery",
    "<Toolbox>/Xtns/Piwigo",
    "",
    [
    (PF_FILE, "pInit", "Dossier initial","~/Desktop/"),
    (PF_BOOL, "bAdd", "Ajout seulement ?",1),
    (PF_BOOL, "bOri", "Originaux a deplacer vers pwg_high ?",1),
    (PF_INT, "iTN", "Taille des vignettes (pixel)",64),
    (PF_INT, "iStd", "Taille standard (pixel)",640),
    ],
    [],
    resize)

main()

Il faut l'enregistrer dans
~/.gimp-2.6/plug-ins/
Et le rendre executable (Clic droit > Propriété > Permission)

Au (re)-demarrage de Gimp, il devrait y avoir un lien dans :
Fenetre image > Filtres > Piwigo

Hors ligne