It is currently 07 Jul 2020, 02:23

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

"Ghost" python plugin?

GIMP or GIMP LEARN forum related Questions
vndep
Forum Member

"Ghost" python plugin?

Post#1 by vndep » 20 Jun 2019, 01:46


Noob here. I successfully ran sample (Hello World) in its own plug in folder. I have added different versions of the file in the same folder (sample1, sample2, etc).

For some reason, what is or is not in the plug in folder may or may not show up in the pythonfu drop down menu.

I have quit and restarted GIMP several times and experimented with moving files around. So I now have the following unexpected situation:

(a) in GIMP, "sample" is available in the pythonfu drop down menu (and runs properly) but "sample" is not in the plug in folder.

(b) "sample1" and "sample2" are in the plug in folder, but do not appear in the pythonfu drop down menu.
GIMP Learn rocks...
0

tim
GL Blogger

Post#2 by tim » 20 Jun 2019, 03:44


If you're on Linux, you have to set the file(.py files) as executable.
And they won't show up if GIMP runs into errors while loading them.
To know for sure what went wrong is to execute GIMP from command-line and see what GIMP complaints about as it'll show errors.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

vndep
Forum Member

Post#3 by vndep » 20 Jun 2019, 09:27


Thanks for your response! ... I'm in Windows, if it matters.

I know how to call a command prompt; what command will run GIMP?
GIMP Learn rocks...
0

tim
GL Blogger

Post#4 by tim » 20 Jun 2019, 13:00


look at properties of your GIMP icon that you usually click to run GIMP.
It'll have the command line name.
like gimp-2.10.exe for example.
or according to the net it's something like "c:\program files\gimp 2\bin\gimp-2.10" --verbose --console-messages"
depends where your gimp is installed. your path might be the same/different.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

vndep
Forum Member

Post#5 by vndep » 21 Jun 2019, 11:50


Fixed the prior problem: creating variants of scripts without giving each variant a unique name for the menu.

I am wondering if you might be able to give me a pointer on where the code below is wrong. For this line:

textlayerval = pdb.gimp_text_fontname(imagepath, drawableFLAG, xval, yval, text, borderval, antialiasFLAG, sizeval, sizetypeval, fontnameval)

It throws the error: 'Plug-in 'SamplemyotherBIGscript' left image undo in inconsistent state, closing open undo groups.'

Here's the script (a modification of Tin Tran's sample):

Code: Select all

#!/usr/bin/env python

import time
from gimpfu import *

def python_sample_myotherscript(image, layer) : #FUNCTION DEFINITION
	pdb.gimp_image_undo_group_start(image)
	pdb.gimp_context_push()
	#YOUR CODE BEGINS=======================


	filename = 'G:/Users/Star/Dropbox/Projects/Stock photos/Word lists/sample.txt'
	imagepath = 'G:/Users/Star/Dropbox/Projects/Stock photos/blue-clouds-day-53594.jpg'
	drawableFLAG = -1
	xval = 500
	yval = 500
	borderval = 0 
	antialiasFLAG = FALSE
	sizeval = 4
	sizetypeval = 0
	fontnameval = 'Arial'

	lines = open(filename).read().split('\n')
	for i in range(len(lines)):

		text = lines[i]
		pdb.gimp_message('TEXT = ' + text)
		time.sleep(1)
		pdb.gimp_message('CREATE LAYER')
		time.sleep(1)
# ERROR IS THROWN AT THE NEXT LINE
		textlayerval = pdb.gimp_text_fontname(imagepath, drawableFLAG, xval, yval, text, borderval, antialiasFLAG, sizeval, sizetypeval, fontnameval)
		time.sleep(1)
		pdb.gimp_message('TRY TO DELETE LAYER')
		time.sleep(1)
		pdb.gimp_item_delete(textlayerval)
		time.sleep(1)
		pdb.gimp_message('LAYER DELETED')
		time.sleep(1)
		


	#YOUR CODE ENDS ========================
	pdb.gimp_context_pop()
	pdb.gimp_image_undo_group_end(image)
	pdb.gimp_displays_flush()
    #return

register(
	"python_fu_sample_myotherscript",
	"Sample Python Fu Script",
	"Sample Python Fu Script...",
	"Tin Tran",
	"Tin Tran",
	"Oct 2017",
	"<Image>/Python-Fu/Sample_myotherBIGscript...",
	"*",      # Create a new image, don't work on an existing one
	[ 
	#INPUT BEGINS
	#(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
	#(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
	#(PF_SPINNER, "border_width", "Border Width (bevelled width):", 10, (0, 500, 1)),
	#(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
	#(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
	#INPUT ENDS
	],
	[],
	python_sample_myotherscript)

main()
GIMP Learn rocks...
0

tim
GL Blogger

Post#6 by tim » 21 Jun 2019, 13:31


I know documentation says that drawableFLAG is -1 but for pdb procedure calls if something isn't use you have to use None
so set drawableFLAG to None

Code: Select all

drawableFLAG = None
also the first parameter to the function should be image, not imagepath
if you want to do something with the image file in your path, you have to open it up using soemthing like pdb.file_jpeg_load
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

vndep
Forum Member

Post#7 by vndep » 21 Jun 2019, 18:41


Thanks, again. I am making slow but forward progress on this.

The code below doesn't throw any errors, but it doesn't achieve the desired objective, either.
The objective is to see the .jpg file with "Sample Text" written on it.
I am attempting to do this by (a) creating an image object out of the .jpg file, (b) using pdb.gimp_text_fontname to create the layer with the image and text.

I run the script on a new image, it runs successfully (I can see the messages appearing) but no new layer is created and I don't see anything but the original new image.

Thanks in advance for your help!

Here's the code:

Code: Select all

#!/usr/bin/env python


import time
from gimpfu import *

def python_sample_scriptC(image, layer) : #FUNCTION DEFINITION
	pdb.gimp_image_undo_group_start(image)
	pdb.gimp_context_push()
	#YOUR CODE BEGINS=======================

	imagepath = 'G:/Users/Star/Dropbox/Projects/Stock photos/blue-clouds-day-53594.jpg'
	text = 'SAMPLE TEXT'
	drawableFLAG = None
	xval = 10
	yval = 10
	borderval = 0 
	antialiasFLAG = FALSE
	sizeval = 10
	sizetypeval = 1
	fontnameval = 'Arial'

	pdb.gimp_message('LOAD IMAGE')
	imageobj = pdb.file_jpeg_load(imagepath, imagepath)
	pdb.gimp_message('CREATE LAYER')
	textlayerval = pdb.gimp_text_fontname(imageobj, drawableFLAG, xval, yval, text, borderval, antialiasFLAG, sizeval, sizetypeval, fontnameval)
#	time.sleep(10)
#	pdb.gimp_message('TRY TO DELETE LAYER')
#	pdb.gimp_item_delete(textlayerval)
#	pdb.gimp_message('LAYER DELETED')

		


	#YOUR CODE ENDS ========================
	pdb.gimp_context_pop()
	pdb.gimp_image_undo_group_end(image)
	pdb.gimp_displays_flush()
    #return

register(
	"python_fu_sample_scriptC",
	"Sample Python Fu Script",
	"Sample Python Fu Script...",
	"Tin Tran",
	"Tin Tran",
	"Oct 2017",
	"<Image>/Python-Fu/Sample_scriptC...",
	"*",      # Create a new image, don't work on an existing one
	[ 
	#INPUT BEGINS
	#(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
	#(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
	#(PF_SPINNER, "border_width", "Border Width (bevelled width):", 10, (0, 500, 1)),
	#(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
	#(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
	#INPUT ENDS
	],
	[],
	python_sample_scriptC)

main()
GIMP Learn rocks...
0

tim
GL Blogger

Post#8 by tim » 21 Jun 2019, 20:09


when you post code you should use the 5th button to post code then it keeps your format like indents and stuff.

After loading the jpeg, you'll need to call
pdb.gimp_display_new(imageobj)
to create a new display that displays your loaded jpeg.
If you want to save the result you'll need to use pdb.file_jpeg_save() for example but i think you have to flatten your image or merge visible layers first so that your result is on the same layer that way you can save that layer as a jpeg or png or whatever.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

tim
GL Blogger

Post#9 by tim » 21 Jun 2019, 20:19


here's the code

Code: Select all

#!/usr/bin/env python


import time
from gimpfu import *

def python_sample_scriptC(image, layer, imagepath) : #FUNCTION DEFINITION
	pdb.gimp_image_undo_group_start(image)
	pdb.gimp_context_push()
	#YOUR CODE BEGINS=======================

	#imagepath = 'G:/Users/Star/Dropbox/Projects/Stock photos/blue-clouds-day-53594.jpg'
	text = 'SAMPLE TEXT'
	drawableFLAG = None
	xval = 10
	yval = 10
	borderval = 0 
	antialiasFLAG = FALSE
	sizeval = 10
	sizetypeval = 1
	fontnameval = 'Arial'

	pdb.gimp_message('LOAD IMAGE')
	imageobj = pdb.file_jpeg_load(imagepath, imagepath)
	pdb.gimp_display_new(imageobj)
	pdb.gimp_message('CREATE LAYER')
	textlayerval = pdb.gimp_text_fontname(imageobj, drawableFLAG, xval, yval, text, borderval, antialiasFLAG, sizeval, sizetypeval, fontnameval)
#	time.sleep(10)
#	pdb.gimp_message('TRY TO DELETE LAYER')
#	pdb.gimp_item_delete(textlayerval)
#	pdb.gimp_message('LAYER DELETED')

		


	#YOUR CODE ENDS ========================
	pdb.gimp_context_pop()
	pdb.gimp_image_undo_group_end(image)
	pdb.gimp_displays_flush()
    #return

register(
	"python_fu_sample_scriptC",
	"Sample Python Fu Script",
	"Sample Python Fu Script...",
	"vndep",
	"vndep",
	"June 2019",
	"<Image>/Python-Fu/Sample_scriptC...",
	"*",      # Create a new image, don't work on an existing one
	[ 
	#INPUT BEGINS
	(PF_FILENAME, "imagepath", "Image File Path:", 0),
	#(PF_OPTION, "arrow_side", "Arrows Ends:", SIDE_END, SIDE_NAMES),
	#(PF_TOGGLE, "arrow_close", "Arrows Close:", 0),
	#(PF_SPINNER, "border_width", "Border Width (bevelled width):", 10, (0, 500, 1)),
	#(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 6, (-4096,4096,1)),
	#(PF_SPINNER, "shadow_blur_radius", "Shadow Blur Radius:", 15, (0,1024,1)),
	#(PF_SPINNER, "shadow_opacity", "Shadow Opacity:", 100, (0,100,1)),
	#INPUT ENDS
	],
	[],
	python_sample_scriptC)

main()
with a filename paramater for more parameter types see: viewtopic.php?p=11157#p11157
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

tim
GL Blogger

Post#10 by tim » 21 Jun 2019, 20:34


Thanks for asking btw (It gives me opportunity to be of your service :D)
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0


GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 7 guests