Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 5,911
» Latest member: kristalyn
» Forum threads: 7,361
» Forum posts: 40,078
Full Statistics
|
|
|
Python-Fu - os.path not working |
Posted by: BaconWizard17 - 01-10-2024, 09:38 PM - Forum: Scripting questions
- Replies (5)
|
 |
Hi all,
I'm trying to set up a Python-Fu script that will get the file path of the current file, save the file, and then return the folder and file name of the file. For some reason, though, the os.path operations that I'm including don't appear to be working. Here's the code:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from gimpfu import*
def getPathSave(image, layer):
pdb.gimp_message("Test")
filePath = pdb.gimp_image_get_filename(image)
pdb.gimp_message("filePath = " + str(filePath))
pdb.gimp_file_save(image, layer, filePath, filePath)
pathCheck = os.path.exists(filePath) # sanity check to make sure that it's actually giving me a path
pdb.gimp_message("pathCheck = " + str(pathCheck))
folderName = os.path.dirName(filePath)
pdb.gimp_message("folderName = " + str(folderName))
fileName = os.path.basename(filePath)
pdb.gimp_message("fileName = " + str(fileName))
#return folderName, fileName
register(
"python_fu_marvelmods_basic_get_path_save",
"Saves the file and collects file path information. Returns the folder that the file is in, as well as its name (without the extension).",
"Saves the file and collects file path information. Returns the folder that the file is in, as well as its name (without the extension).",
"BaconWizard17",
"BaconWizard17",
"January 2024",
"Get File Path and Save",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, "drawable", "Layer, mask, or channel", None)
],
[
#(PF_STRING, "folderName", "The folder that the file is in"),
#(PF_STRING, "fileName", "The file name")
],
getPathSave,
menu='<Image>/Marvel Mods/Basic Procedures'
)
main()
I took this code from a finished script that already works. It's a process that I use in a lot of other scripts, so I'm trying to consolidate it into one and just call this instead of copying the same code every time. But I can't get it to work on its own for whatever reason. I haven't even gotten to the point of returning the values (you can see that they're commented out). The first three pdb.gimp_message scripts work and will show something in the error console, but the last two don't show anything. It seems that the values aren't getting collected, so there's nothing to return. But I have no clue why it's not working.
I've tried using this method to debug the script, but it just crashes the Python-Fu console for some reason, so I haven't gotten any luck there.
I'm on Windows 10 and using GIMP 2.10.36. Any help would be seriously appreciated!
|
|
|
GEGL Drop Shadow: A New Attempt |
Posted by: BaconWizard17 - 01-10-2024, 04:17 PM - Forum: Scripting questions
- Replies (1)
|
 |
Hi all,
I've been trying to figure out how to set up a script that will do a drop shadow with the GEGL drop shadow filter. This is something I've wanted to do in the past, but didn't get any traction on it. Since then, I've found what seems like a possible solution, but I'm having issues actually implementing it.
I did this thread with a way to use GEGL with Python-Fu (is there a more current way to do this?), and I also found this set of scripts that transcribe the various GEGL operations into individual Python-Fu scripts (again, is there something more current than this?). I have both scripts in my Plug-Ins folder. If I use the drop shadow script from the "GEGL as Python" toolbar in Gimp, it works great. My question is how to properly code that into a script.
Here's the drop shadow script from MareroQ:
Code:
def gegl_dropshadow(image, layer, shadow_offset_x, shadow_offset_y, shadow_blur, grow_shape, grow_radius, color_s, shadow_opacity):
color_to_gegl=rgb_to_hex(color_s)
if grow_shape==0:
grow_s='square'
if grow_shape==1:
grow_s='circle'
if grow_shape==2:
grow_s='diamond'
gegl_graph_string="gegl:dropshadow x=%d y=%d radius=%d grow-shape=%s grow-radius=%d color=%s opacity=%f" % (shadow_offset_x, shadow_offset_y, shadow_blur,grow_s,grow_radius, color_to_gegl, shadow_opacity)
pdb.python_fu_gegl_graph(image, layer, gegl_graph_string)
register(
"python_fu_gegl_dropshadow",
"GEGL to Python. Works on the active layer",
"Creates a dropshadow effect on the input buffer",
"Auto Author",
"Auto Author",
"Auto Generated Dated",
"<Image>/GEGL as Python/gegl-dropshadow...", #Menu path
"*",
[
(PF_SPINNER, "shadow_offset_x", "Shadow Offset X:", 5, (-1000, 1000, 1)),
(PF_SPINNER, "shadow_offset_y", "Shadow Offset Y:", 5, (-1000, 1000, 1)),
(PF_SPINNER, "shadow_blur", "Shadow Blur Radius:", 5, (0, 300, 1)),
(PF_OPTION, "grow_shape", "Grow Shape: ", 0, [" Square "," Circle ", " Diamond "]),
(PF_SPINNER, "grow_radius", "Grow Radius:", 5, (-100, 100, 1)),
(PF_COLOR, "color_s", "Color:", (0, 0, 0)),
(PF_FLOAT, "shadow_opacity", "Shadow Opacity (default:1.5, 0..2):", 1.5) # (0, 2, 0.01)),
],
[],
gegl_dropshadow)
Here's my attempt at implementing that into my own script:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import*
def generate_hud_outline(image, layer):
pdb.gimp_image_undo_group_start(image)
pdb.gimp_selection_none(image)
pdb.python_fu_gegl_dropshadow(image, layer, 0.00, 0.00, 2.00, "circle", 1, gimpcolor.RGB(0,0,0), 1.25)
pdb.gimp_displays_flush()
pdb.gimp_image_undo_group_end(image)
register(
"python_fu_marvelmods_common_generate_hud_outline",
"Generates an outline for a conversation portrait.",
"Generates an outline for a conversation portrait.",
"BaconWizard17",
"BaconWizard17",
"January 2024",
"Generate Conversation Portrait (HUD) Outline",
"*",
[
(PF_IMAGE, "image", "Input image", None),
(PF_DRAWABLE, 'drawable', 'Layer, mask or channel', None)
],
[],
generate_hud_outline,
menu='<Image>/Marvel Mods/Utilities'
)
main()
However, this script keeps failing, and I'm not sure why. If I run it from the toolbar, the error console gives an error that says
"GIMP Warning
Plug-in 'Generate Conversation Portrait (HUD) Outline' left image undo in inconsistent state, closing open undo groups."
If I try to run it in the Python-Fu console using this method, it crashes and I get the following error in the error console:
"GIMP Error
Plug-in crashed: "python-console.py"
(C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins\python-console\python-console.py)
The dying plug-in may have messed up GIMP's internal state. You may want to save your images and restart GIMP to be on the safe side."
Any thoughts on what I could be doing wrong? I'm using GIMP 2.10.36 on Windows 10.
|
|
|
Get rid of thin pic border after Crop |
Posted by: GMP - 01-09-2024, 07:19 PM - Forum: General questions
- Replies (4)
|
 |
I cropped a pic and it looks fine except I didn't quite get the very outside border of the pic. So there's a tiny line at the top and the right. I did it right on the left. I tried to fix it with the Crop tool, but it didn't work. I tried the Eraser tool, but I couldn't get it to work, since I've never used it before. What the best way to fix this?
I tried the Eraser tool again, and this time it worked. Not sure what I was doing wrong, except this time I chose the tool from the icons on the left
|
|
|
|