It is currently 21 Jan 2018, 06:23

GIMP Python Fu ScriptsStroke Paths with Gradient Script for GIMP (Showcase | Slideshow)

Share your Python Fu scripts for GIMP here
User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/8
Posts: 2071
Joined: 25 Sep 2016, 17:16
Cash on hand: 7,180.19 GLP
Bank: 42,250.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1106
x 240
Contact:
Canada

Stroke Paths with Gradient Script for GIMP

Post#1 by tim » 04 Oct 2017, 16:36


I always knew about Ofnuts's path-inbetweener-0.2.py script.
Always thought it was cool but never really had a chance to use it.
Hopefully now, with this script, people (including me) will use it more.
Now I don't know if such a script already exists, but if it does (I do not know about it). I only thought of this script after writing Stroke Path with Gradient (with miter [sharp edges]) Script for Pegleg44.

This script will stroke all your VISIBLE paths.

:download:
stroke_paths_with_gradient.zip #
zipped .py file (unzip, put in your GIMP's plug-ins/ folder)
(2.73 KiB) Downloaded 37 times
:download:
stroke_paths_with_gradient(2).zip #
version 2. Fixed error so that it would work on Linux as well.
(2.8 KiB) Downloaded 29 times

Script Menu Location: Python-Fu/Stroke Paths with Gradient...

Script Option:
stroke_paths_with_gradient_options.jpg
stroke_paths_with_gradient_options.jpg # (81.66 KiB) Viewed 530 times (Watermarked | Thumbnail)
Instructions:
1. Create multiple paths (using Ofnut's path-inbetween script).
2. Run This Script (Python-Fu/Stroke Paths with Gradient...). Select Gradient/Reverse/Line Width.
3. Hit "OK". It'll stroke all your VISIBLE paths with selected gradient.
4. Also, a recent .svg file entry will be added to your Document History. You can open it (import .svg) by going to Files > Open Recent and click on the first .svg you see.

Example results:
stroke_paths_with_gradient_example_01.png
example with start path, end path and a guide path
stroke_paths_with_gradient_example_01.png # (42.05 KiB) Viewed 530 times (Watermarked | Thumbnail)
stroke_paths_with_gradient_example_02.png
example with start path and end path.
stroke_paths_with_gradient_example_02.png # (50.46 KiB) Viewed 530 times (Watermarked | Thumbnail)
0 x



aka Tin
Image gimplearn.net                                              

Registered members enjoy ads-free content
User avatar
Pegleg44
Forum Member
View: Showcase | Slideshow
Topic Posts: 2/8
Posts: 43
Joined: 28 Nov 2016, 19:12
Cash on hand: 258.13 GLP
x 11
Gimp Nation

Post#2 by Pegleg44 » 04 Oct 2017, 17:54


There is a stroke multiple visible paths plug-in that I've been using for a couple of years now. But I will get yours too.

Here it is:

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# GIMP plugin to stroke all visible paths on separate layers
# (c) Ofnuts 2014
#
#   History:
#
#   v0.0: 2012-06-22: Initial version
#   v0.1: 2013-08-04: Add gradient support
#   v0.2: 2013-08-05: Check that there are some paths to stroke
#   v0.3: 2014-10-25: Add stroke/fill and single/multiple layer options

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

def newLayer(image,name,background):
	layer=gimp.Layer(image,name, image.width, image.height,RGBA_IMAGE, 100., NORMAL_MODE)
	image.add_layer(layer,0)
	pdb.gimp_drawable_fill(layer,background)	
	return layer

def strokeFillVisiblePaths(image,useGradient,fill,single,background,name):
	pdb.gimp_image_undo_group_start(image)
	pdb.gimp_context_push()
	try:
		colors=None
		singleLayer=None
		savedSelection=None
		if single:
			if name=='':
				name='Stroked/Filled paths'
			singleLayer=newLayer(image, name,background)
		if fill and not pdb.gimp_selection_is_empty(image):
			savedSelection=pdb.gimp_selection_save(image)
			
		strokedPaths=[p for p in image.vectors if p.visible]
		if len(strokedPaths) < 2:
			raise Exception("There should be at least two visible paths")
		if useGradient:
			colors=gimp.gradient_get_uniform_samples(gimp.context_get_gradient(),len(strokedPaths))
		for i,path in enumerate(reversed(strokedPaths)):
			if colors:
				pdb.gimp_context_set_foreground(colors[i])
				pdb.gimp_context_set_opacity(100*colors[i][3])
			if singleLayer:
				layer=singleLayer
			else:
				layer=newLayer(image,path.name+' '+name,background)
			if fill:
				pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,path)
				pdb.gimp_edit_bucket_fill(layer,FG_BUCKET_FILL,NORMAL_MODE,100.,0.,0,0,0)
			else:
				pdb.gimp_edit_stroke_vectors(layer,path)

		if fill:
			pdb.gimp_selection_none(image)
			if savedSelection:
				pdb.gimp_image_select_item(image,CHANNEL_OP_REPLACE,savedSelection)
				pdb.gimp_image_remove_channel(image,savedSelection)
			
        except Exception as e:
		print e.args[0]
		pdb.gimp_message(e.args[0])

	pdb.gimp_context_pop()
	pdb.gimp_image_undo_group_end(image)
	pdb.gimp_displays_flush()
	return;
	
### Registration
whoiam='\n'+os.path.abspath(sys.argv[0])

register(
	'stroke-fill-visible-paths',
	'Stroke or fill visible paths...'+whoiam,
	'Stroke or fill visible paths',
	'Ofnuts',
	'Ofnuts',
	'2014',
	'Stroke or Fill Multiple Visible Paths',
	'*',
	[
		(PF_IMAGE, 'image', 'Input image', None),
		(PF_OPTION,'useGradient','Color',0,['Foreground color','From gradient']),
		(PF_OPTION,'fill','Stroke/Fill', 0,['Stroke','Fill']),
		(PF_OPTION,'single','Layers',0,['Multiple','Single']),
		(PF_OPTION,'background','Background fill', 1, ['Foreground color','Background color','White','Transparent','Pattern']),
		(PF_STRING,'name','Layer Name or Name suffix', ''),
	],
	[],
	strokeFillVisiblePaths,
	menu='<Image>/HEIGHT TOOLS',
)

main()

0 x




User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/8
Posts: 2071
Joined: 25 Sep 2016, 17:16
Cash on hand: 7,180.19 GLP
Bank: 42,250.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1106
x 240
Contact:
Canada

Post#3 by tim » 04 Oct 2017, 19:03


Ah, what do you know? one already exists. :D
Or at least very similar.
Well now you have another variation, where you get an .svg just in case you want to use it Inkscape or something.
0 x



aka Tin
Image gimplearn.net                                              

User avatar
Pat625
Script Tester
View: Showcase | Slideshow
Topic Posts: 1/8
Posts: 2049
Joined: 27 Sep 2016, 20:35
Cash on hand: 11,979.76 GLP
Gender: Gal
Location: USA
Operating System: Windows
GIMP Version: 2.8.22
x 7
x 430
United States of America

Post#4 by Pat625 » 04 Oct 2017, 21:27


Never hurts to have an extra script to choose, Tin!
TinTranStroke Mult.Paths.png
TinTranStroke Mult.Paths.png # (347.43 KiB) Viewed 504 times (Watermarked | Thumbnail)
TinTranStroke Mult.Paths.Paisley.png
TinTranStroke Mult.Paths.Paisley.png # (214.4 KiB) Viewed 504 times (Watermarked | Thumbnail)
1 x




User avatar
RJKD
Tutorial Creator
View: Showcase | Slideshow
Topic Posts: 2/8
Posts: 1280
Joined: 03 Oct 2016, 06:01
Cash on hand: 8,896.25 GLP
Bank: 0.00 GLP
Gender: Guy
Location: Sheffield UK
Operating System: Windows
GIMP Version: 2.8.20
x 1405
x 195
Contact:
Great Britain

Post#5 by RJKD » 05 Oct 2017, 03:22


Thankyou for yet another useful script T. I use 'Fill or stroke visible paths' found under Image, this gives option to use gradient, sorry for such a dumb question but how do the filters differ?
Here's an older image using that script...
Led_Zeppelin3.jpg
Led_Zeppelin3.jpg # (113.7 KiB) Viewed 490 times (Watermarked | Thumbnail)
This is the script
stroke-visible-paths-0.6.zip #
(2.06 KiB) Downloaded 8 times
0 x




User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 3/8
Posts: 2071
Joined: 25 Sep 2016, 17:16
Cash on hand: 7,180.19 GLP
Bank: 42,250.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1106
x 240
Contact:
Canada

Post#6 by tim » 05 Oct 2017, 07:33


Ofnuts script allows single layer or multiple layers and uses active brush to stroke the path or fill the path.
My script strokes path like line stroke using svg on a single layer, and you get an .svg file.
0 x



aka Tin
Image gimplearn.net                                              

User avatar
Pegleg44
Forum Member
View: Showcase | Slideshow
Topic Posts: 2/8
Posts: 43
Joined: 28 Nov 2016, 19:12
Cash on hand: 258.13 GLP
x 11
Gimp Nation

Post#7 by Pegleg44 » 05 Oct 2017, 07:58


And Tins script gives the ability to change stroke size and miters the edges which can be useful.
0 x




Post Reply

Last 20 Members Who Visited This Topic

User avatar Pat625 (18), User avatar tim (27), User avatar Issabella (2), User avatar Wallace (2), User avatar Pegleg44 (7), User avatar RJKD (6), User avatar gnerd (4), User avatar animicule (1)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: tim
2: Pat625
3: Ella
4: oldmangrumpy
5: gnerd
6: Issabella
7: Pat625

Who is online

Users browsing this forum: No registered users and 1 guest