| Welcome, Guest |
You have to register before you can post on our site.
|
|
|
| script not available |
|
Posted by: Zydelum - 07-10-2025, 04:33 PM - Forum: Extending the GIMP
- No Replies
|
 |
Hi,
Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
gi.require_version('Gegl', '0.4') # Gegl est utilisé pour les opérations de bas niveau sur les pixels
from gi.repository import Gegl
from gi.repository import GObject
from gi.repository import GLib
import sys
import math # Pour la fonction sqrt (racine carrée) dans le calcul de la différence de couleur
# Fonctions de traduction (standard pour les plugins GIMP)
def N_(message): return message
def _(message): return GLib.dgettext(None, message)
class CleanAndRegularize (Gimp.PlugIn):
## GimpPlugIn virtual methods ##
# Cette méthode est appelée par GIMP au démarrage pour savoir quels plugins sont disponibles
def do_query_procedures(self):
# Retourne une liste des noms de procédures que ce plugin fournit
return [ "plug-in-clean-and-regularize" ]
# Cette méthode est appelée pour créer une instance de la procédure
def do_create_procedure(self, name):
# Crée une nouvelle procédure d'image
procedure = Gimp.ImageProcedure.new(self, name,
Gimp.PDBProcType.PLUGIN,
self.run, None)
# Définit les types d'images sur lesquels le plugin peut opérer
procedure.set_image_types("*") # Peut opérer sur n'importe quel type d'image
# Définit la sensibilité du plugin (nécessite un calque sélectionné)
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE)
# Définit le texte qui apparaîtra dans le menu GIMP
procedure.set_menu_label(_("Nettoyer et Régulariser..."))
# Définit le chemin dans le menu GIMP
procedure.add_menu_path('<Image>/Filters/Ma_Regularisation/')
# Ajoute la documentation (visible dans le navigateur de procédures)
procedure.set_documentation(_("Nettoie une image en rendant transparents les pixels en dehors d'une couleur sélectionnée, puis régularise la forme restante."),
_("Rend transparents les pixels en dehors d'une couleur sélectionnée et régularise la forme restante."),
name)
# Attribution de l'auteur
procedure.set_attribution("Votre Nom", "Votre Nom", "2025")
# Ajoute les paramètres de la procédure (ceux qui apparaissent dans la boîte de dialogue)
procedure.add_argument_from_property(GObject.Property(
"target-color", "Couleur à conserver",
"La couleur cible à conserver dans l'image.",
GObject.TYPE_JSUINT64, # Type de propriété pour la couleur (RGBA 64 bits)
Gimp.RGB(255, 255, 255).to_rgba(), # Valeur par défaut (blanc)
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY
))
procedure.add_argument_from_property(GObject.Property(
"tolerance", "Tolérance de couleur (0-255)",
"La tolérance pour la comparaison des couleurs (0-255).",
GObject.TYPE_INT, # Type entier
30, # Valeur par défaut
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
minimum=0, maximum=255
))
procedure.add_argument_from_property(GObject.Property(
"operation-type", "Opération de régularisation",
"Le type d'opération de régularisation à appliquer.",
GObject.TYPE_INT, # Type entier pour l'option
0, # Valeur par défaut (0 = Aucune)
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
# Les options sont définies par des paires valeur/label
blurb_values=["Aucune", "Érosion de la sélection", "Dilatation de la sélection"]
))
return procedure
# La méthode 'run' est le cœur du plugin, exécutée lorsque l'utilisateur lance le plugin
def run(self, procedure, run_mode, image, drawables, config, run_data):
# Vérifie qu'un seul calque est sélectionné
if len(drawables) != 1:
msg = _("Procedure '{}' only works with one drawable.").format(procedure.get_name())
error = GLib.Error.new_literal(Gimp.PlugIn.error_quark(), msg, 0)
return procedure.new_return_values(Gimp.PDBStatusType.CALLING_ERROR, error)
else:
drawable = drawables[0]
# Récupère les valeurs des paramètres de la configuration
target_color_rgba = config.get_property("target-color")
# Convertit la couleur RGBA 64 bits en Gimp.RGB pour un accès facile
target_color_gimp_rgb = Gimp.RGB()
target_color_gimp_rgb.parse_rgba(target_color_rgba)
target_r = target_color_gimp_rgb.red_int
target_g = target_color_gimp_rgb.green_int
target_b = target_color_gimp_rgb.blue_int
tolerance = config.get_property("tolerance")
operation_type = config.get_property("operation-type")
# Début de l'opération GIMP (pour l'historique d'annulation)
image.undo_group_start()
Gimp.progress_init(_("Traitement de l'image..."))
# Assurez-vous que le calque a un canal alpha pour la transparence
if not drawable.has_alpha():
drawable.add_alpha()
# --- Étape 1 : Rendre transparent les pixels hors couleur cible ---
width = drawable.get_width()
height = drawable.get_height()
# Utilisation de Gegl.Buffer pour un accès aux pixels plus performant et moderne
# Obtient le buffer du calque (le contenu des pixels)
buffer = drawable.get_buffer()
# Crée un buffer d'ombre pour les modifications (meilleure pratique pour les plugins)
shadow_buffer = drawable.get_shadow_buffer()
# Accès direct aux pixels via Gegl.Buffer.get_pixel() et Gegl.Buffer.set_pixel()
# C'est plus lent que les opérations GEGL natives, mais plus simple pour ce type de logique
# Pour des performances extrêmes sur de très grandes images, il faudrait utiliser des opérations GEGL complètes.
for y in range(height):
Gimp.progress_update(float(y) / height) # Met à jour la barre de progression
for x in range(width):
# Récupère le pixel du buffer original
pixel_data = buffer.get_pixel(x, y)
# Les données de pixel sont un tuple (r, g, b, a) où chaque composante est un float de 0.0 à 1.0
r, g, b, a = pixel_data[0], pixel_data[1], pixel_data[2], pixel_data[3]
# Convertit les floats (0.0-1.0) en entiers (0-255) pour la comparaison de tolérance
current_r = int(r * 255)
current_g = int(g * 255)
current_b = int(b * 255)
# Calculer la différence de couleur (distance euclidienne)
diff = math.sqrt((current_r - target_r)**2 + (current_g - target_g)**2 + (current_b - target_b)**2)
if diff > tolerance:
# Rendre le pixel transparent (alpha = 0.0)
shadow_buffer.set_pixel(x, y, (r, g, b, 0.0))
else:
# Conserver le pixel tel quel
shadow_buffer.set_pixel(x, y, (r, g, b, a))
# Applique les modifications du buffer d'ombre au calque
drawable.merge_shadow(True)
# Met à jour la zone modifiée pour l'affichage
drawable.update(0, 0, width, height)
# --- Étape 2 : Régulariser la forme restante ---
# Utilisation des fonctions PDB de GIMP pour les opérations de sélection et de remplissage
if operation_type == 1: # Érosion de la sélection
# Crée une sélection à partir du canal alpha du calque
image.set_selection_mask(drawable.get_alpha_mask())
# Rétrécit la sélection
Gimp.selection_shrink(image, 2) # Rétrécir de 2 pixels
# Inverse la sélection pour remplir l'extérieur
image.invert_selection()
# Remplir la sélection inversée avec de la transparence
drawable.fill(Gimp.FillType.TRANSPARENT)
# Désélectionne tout
image.set_selection_mask(None)
elif operation_type == 2: # Dilatation de la sélection
image.set_selection_mask(drawable.get_alpha_mask())
# Agrandit la sélection
Gimp.selection_grow(image, 2) # Agrandir de 2 pixels
image.invert_selection()
drawable.fill(Gimp.FillType.TRANSPARENT)
image.set_selection_mask(None)
# Rafraîchir l'affichage de toutes les fenêtres GIMP
Gimp.displays_flush()
image.undo_group_end() # Fin de l'opération GIMP (pour l'historique d'annulation)
Gimp.progress_end()
# Retourne les valeurs de succès
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
# Enregistre le plugin dans GIMP
Gimp.main(CleanAndRegularize.__gtype__, sys.argv)
Here's a Python script that's supposed to:
- select a color from an image
- make other colors transparent except for very similar ones
- smooth (delete, add pixels) in the remaining areas so that the angles are sharp in detail
I placed this script in a folder with the same name, but the Gimp3 console returns some errors
Can you fix this script?
thanks
|
|
|
| script does not appears in Gimp3 filters |
|
Posted by: Zydelum - 07-10-2025, 01:01 AM - Forum: Extending the GIMP
- Replies (2)
|
 |
Hi,
On macOS, this minimalist Python script for Gimp3 doesn't appear in Gimp3 Filters
I placed this script in Plugins and then made it executable.
Why?
Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
from gi.repository import GLib
import sys
def N_(message): return message
def _(message): return GLib.dgettext(None, message)
class MinimalTest (Gimp.PlugIn):
def do_query_procedures(self):
return [ "plug-in-minimal-test" ]
def do_create_procedure(self, name):
procedure = Gimp.ImageProcedure.new(self, name,
Gimp.PDBProcType.PLUGIN,
self.run, None)
procedure.set_image_types("*")
procedure.set_menu_label(_("Minimal Python 3 Test"))
procedure.add_menu_path('<Image>/Filters/Development/My Minimal Tests/')
procedure.set_documentation(_("A very minimal test for Python 3 plugins."),
_("A very minimal test for Python 3 plugins."),
name)
procedure.set_attribution("Your Name", "Your Name", "2025")
return procedure
def run(self, procedure, run_mode, image, drawables, config, run_data):
Gimp.message("Minimal Python 3 Test Loaded Successfully!")
return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())
Gimp.main(MinimalTest.get_type(), sys.argv)
|
|
|
GEGL Plugins for GIMP 3.0.4 and GIMP 2.10.38 |
|
Posted by: BeaverGEGLFreak - 07-09-2025, 10:55 PM - Forum: Extending the GIMP
- Replies (5)
|
 |
Download GEGL plugins here
https://github.com/LinuxBeaver/LinuxBeaver/releases/
Hello, Its me LinuxBeaver the GEGL plugin guy who is obsessed with everything GEGL. I am here to share my GEGL plugins, as these pic show I make GEGL plugins for GIMP that do text styling and background design as well as more special effects all non-destructive and re-editable of course on GIMP 3. These plugins are recommended to be used on GIMP 3.0.4 but also work on 2.10
![[Image: 463579721-00f9f7e3-31f3-419d-a033-15b99a...UxAvMOBvXA]](https://private-user-images.githubusercontent.com/78667207/463579721-00f9f7e3-31f3-419d-a033-15b99a5d0cd1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTIwOTkzOTMsIm5iZiI6MTc1MjA5OTA5MywicGF0aCI6Ii83ODY2NzIwNy80NjM1Nzk3MjEtMDBmOWY3ZTMtMzFmMy00MTlkLWEwMzMtMTViOTlhNWQwY2QxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNzA5VDIyMTEzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVjZjg1MzEyNDIwZWJhNzNhZDhjM2ZlNGRkYzIzYjNkNjdkOTc1YTBhNjllMDdiY2M1ZTNmOThkZGYxNTI0NWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3Ryb_8wuomzZw1NTZK660tVzQtt07y-iKUxAvMOBvXA)
background design
![[Image: 431530020-827667d9-f62a-4ecb-b795-8a5327...lYxmevJjnc]](https://private-user-images.githubusercontent.com/78667207/431530020-827667d9-f62a-4ecb-b795-8a5327c1ea1e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NTIwOTk0MjEsIm5iZiI6MTc1MjA5OTEyMSwicGF0aCI6Ii83ODY2NzIwNy80MzE1MzAwMjAtODI3NjY3ZDktZjYyYS00ZWNiLWI3OTUtOGE1MzI3YzFlYTFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA3MDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNzA5VDIyMTIwMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxNTZlZmFjMzQ4ZDU4N2M3N2U4ZTg5MzA0N2Q0Yzc3ZTA3NDBhOGY1MzEwNGNkZTgxNTQzZGVlZTY0N2Y2MjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ciVXSvXXZLitmnZgV1ZXUgDhdPlurraM4lYxmevJjnc)
There is around 125 natural GEGL plugins total and they can all be downloaded here
https://github.com/LinuxBeaver/LinuxBeaver/releases/
Users have the option to choose between source code, windows and linux binaries as well as a choice between the top 50 plugins or all 125 plugins.
Also users may visit an individual plugin download page like
https://github.com/LinuxBeaver/GEGL-GIMP.../releases/
and download a plugin individually.
GEGL Plugins DO NOT go in the normal GIMP plugins folder instead they go in places like this
Windows
Code:
C:\Users\(USERNAME)\AppData\Local\gegl-0.4\plug-ins
Linux
Code:
~/.local/share/gegl-0.4/plug-ins
Linux (Flatpak includes Chromebook)
Code:
~/.var/app/org.gimp.GIMP/data/gegl-0.4/plug-ins
then restart GIMP and go to "GEGL operation" to find the new plugins if on GIMP 2.10 or if on GIMP 3 look in the menu under filters>render>text styling, filters>text styling and other places.
Also if you didn't notice there are also about 50 more AI generated GEGL plugins on a seperate download page but I really don't like to endorse them. They were made by a machine machine not me, and they are separate from the normal download. You can still check them out of you want they go in the same folder.
|
|
|
| GIMP - 3.0.4 - perspective transformation |
|
Posted by: MichalStanczyk - 07-09-2025, 12:02 PM - Forum: Gimp 2.99 & Gimp 3.0
- Replies (1)
|
 |
Hi everyone
I installed the new version 3.0.4 and immediately encountered a problem with perspective transformation. It leaves black areas that should be transparent, leaving the background layer visible.
Could anyone point me to a solution? This wasn't an issue in the old version, so I hope it's just a matter of changing the settings.
Thank you for your help.
|
|
|
| Layer Mode List in Gimp3 |
|
Posted by: daiappy - 07-07-2025, 10:30 PM - Forum: General questions
- Replies (3)
|
 |
Hello. I'm on Win11. As a long time user of Gimp I'm trying to get my head round Gimp 3. Here are a few Q's and suggestions.
1) In the Layer Mode dropdown list is there a way to: a) reduce the space between each Mode so that all the Modes are visible to choose from? & b) if I choose a Layer Mode from near the bottom of the list, is there a way to return quickly to the top of the list without the need to use the mouse wheel which goes so slowly? If I could see all the Modes I could just click on the top one. This is especially tedious when using Curves.
2) when I do an action/adjustment on a layer, (Curves/Crop etc) I need to keep constantly clicking the Image Window to reactivate it. It wasn't as necessary in Gimp 2.
3) I do like the new 'Save Settings' in the Add Border Filter. Perhaps in the future we will be able to save more than one Add Border setting?
But I do like the NDL's. Thanks to all the devs who have worked towards Gimp 3.
Charles.
|
|
|
Gimp.ParamSpec.int() default value triggers “invalid or out of range” warning |
|
Posted by: owierda - 07-07-2025, 10:45 AM - Forum: Extending the GIMP
- Replies (2)
|
 |
Hi folks — I'm working on a plugin for GIMP 3.0 and running into a strange behavior with Gimp.ParamSpec.int.
When I define a property like seed with:
python
proc.add_argument(
Gimp.ParamSpec.int(
"seed",
"Seed",
"Seed value",
0, # min
9999, # max
9999, # default
Gimp.ParamFlags.READWRITE
)
)
I get this warning at plugin registration:
Warning: value "9999" of type 'gint' is invalid or out of range for property 'seed' of type 'gint'
min <= max => default
The default is clearly within the defined min/max bounds, and all three values (min, max, default) are legitimate. Strangely, the only setup that suppresses this warning is when all three values are **exactly the same** (we call it the triple x same bug), like:
python
0, 0, 0
or
1024, 1024, 1024
Even common combinations like:
python
0, 9999, 0
512, 2048, 1024
or:
python
0, 9999, 5000
cause the warning to appear and as a result, the plug-in is not registered. I’ve searched around but haven’t found an explanation. Is this a known quirk in GIMP’s plugin API? Are there hidden constraints on gint properties that aren’t documented?
Any ideas or workarounds would be appreciated!
Thanks ?
Olaf
|
|
|
|