Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Quick modification of find replace to allow multiple replacement at once with comma separated lists from a spreadsheet/csv.

View gist:5369685
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Chris Mohler
# Multi-replace: Eyecreate
# Copyright 2008 Chris Mohler
# License: GPL v3
# GIMP plugin to perform search and replace on all text layers
 
from gimpfu import *
import re
 
gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
 
def find_and_replace(image, drawable, find, replace, all, case):
layers = image.layers #get image layers
if all: count = 0 #replace all
else: count = 1 #replace only first match
splitFind = find.split(',')
splitReplace = replace.split(',')
splitReplaceCount = 0
for element in splitFind:
if not case: element = re.compile(element, re.I) #case-insentive
for layer in layers:
if pdb.gimp_drawable_is_text_layer(layer): #only act on text layer
haystack = pdb.gimp_text_layer_get_text(layer) # get texr
if haystack == element: #prevents replacing parts of strings
replaced = re.sub(element, splitReplace[splitReplaceCount], haystack, count) # replace text
pdb.gimp_text_layer_set_text(layer, str(replaced)) # set text
splitReplaceCount += 1
 
register(
"python-fu-text-find-and-replace",
"Find and Replace text in all text layers.",
"Find and Replace text in all text layers.",
"Chris Mohler",
"Chris Mohler",
"2008",
"<Image>/Edit/Find & Replace Text...",
"RGB*, GRAY*",
[
(PF_STRING, "find", "Find (comma seperated):", ""),
(PF_STRING, "replace", "Replace (comma seperated):", ""),
(PF_TOGGLE, "all", "Replace All?", True ),
(PF_TOGGLE, "case", "Case Sensitive?", True),
],
[],
find_and_replace,
domain=("gimp20-python", gimp.locale_directory))
 
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.