Welcome, Guest |
You have to register before you can post on our site.
|
|
|
Gimp 3: get indexed of each pixel from a layer = img.layers[0] pdb.gimp_layer |
Posted by: TheInstinct - 04-04-2025, 09:09 PM - Forum: Extending the GIMP
- Replies (6)
|
 |
Hi everybody,
I'm facing a serious problem when porting a plugin I wrote in Gimp 2.10 to Gimp 3.0 in python.
In Gimp 2, I used the following way to the color index of each pixel. It works very well:
Code:
layer = img.layers[0]
region = layer.get_pixel_rgn(0, 0, img.width, img.height, False, False)
pixels = array("B", region[0:img.width, 0:img.height])
pixels contains the index of the color [0;255] which is a byte.
In Gimp 3, you can get access to color information of the layer by using layer.get_buffer(...) but you won't get the color index as you must provide a Babl format. So you will get a color, or luminance in the format you selected "RGB u8" for example, but you won't get the indexes of the colors used by each pixel.
I made research but can't find how to get color index of each pixel. I hope some of you will be able to help me.
Thank you in advance for your support.
|
|
|
Issues with pasting and aligning |
Posted by: accessd - 04-04-2025, 08:26 PM - Forum: Gimp 2.99 & Gimp 3.0
- Replies (2)
|
 |
Hi all,
I'm having trouble performing some basic tasks in Gimp 3. I'm not sure if they're bugs (in which case I will submit a report), or if the functionality has changed and I'm using it the wrong way. I commonly need to splice images of two or more people together. The general process is as follows:
- use the selection tool to select part of image A;
- click Crop to Selection;
- resize the image to match the width or height of the new image I'm creating;
- use the Crop tool to crop a fixed size;
- copy the resulting image and paste it into a new file;
- use Align and Distribute tool to move it to one side of the new image;
- repeat process with image B.
Since I upgraded to Gimp 3, when I copy the cropped image and paste it into a new file, I get all the information from before I used the Crop tool (Step 4). To get around this, I have to use the Copy Visible command, but shouldn't the Crop tool get rid of the rest of the image like the Crop to Selection command does?
Then, when I try to align the pasted layer in the new image, regardless of whether I try to align the layer vertically or horizontally, the Align and Distribute tool aligns the middle of the layer with the edge of the image, so half the layer is always out of view. Is this a bug or am I missing something?
I'm running Gimp 3.0.2 on Ubuntu 24.10.
|
|
|
PyAstro3 |
Posted by: KenS. - 04-04-2025, 09:55 AM - Forum: Gimp 2.99 & Gimp 3.0
- No Replies
|
 |
Has anyone heard whether PyAstro3 will be updated to GIMP 3.0. So far unable to find contact address for author. Take care.
|
|
|
Gimp 3 Flatapak Linux PYTHONPATH is empty |
Posted by: silenuznowan - 04-03-2025, 07:46 PM - Forum: Scripting questions
- Replies (6)
|
 |
I'm trying to get a bash script to run after changing folders.
If I explicitly set the path to the python scripts it runs fine.
If I however omit the explicit path, even though the scripts are in my PYTHONPATH they are not recognized when running without
explicitly using sys.path.append
If I try and get the python path from inside the Gimp shell, it reports no key present instead of printing the PYTHONPATH like it does when not in the Gimp shell.
As stated in the title I have the flatpak version so my question is how do I get it to use my current PYTHONPATH?
Also is it possible to use packages, and if so how. I had a simple package, but when functions were called from a bash script, they would fail with the internal imports in the package failing. An example is below:
Code:
### This should be the command to start Gimp
GIMP_THREE='flatpak run --user org.gimp.GIMP'
# Start gimp with python-fu batch-interpreter
$GIMP_THREE -i --batch-interpreter=python-fu-eval -b - << EOF
import os
import sys
print("PYTHONPATH = " + os.environ['PYTHONPATH'])
EOF
exit(0)
However if on the command line I load a python script that calls the same methods as the bash script it executes fine.
Code:
flatpak run --user org.gimp.GIMP -i --batch-interpreter=python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import pytest;pytest.run()'
I feel like it's something simple i'm missing because I'm not a python programmer. Hopefully someone can help.
Thanks.
|
|
|
Converting the API doc to Python |
Posted by: Ofnuts - 04-03-2025, 09:11 AM - Forum: Tutorials and tips
- No Replies
|
 |
A little bit of C.
In C you have two kinds of data types.
- The "native" ones: int and floats of various lengths, and pointers (memory addresses)
- The "complex" ones (anything else, "structs" or arrays)
When you call a function:
- native types are passed "by value": their value is copied in the call stack
- complex types are passed "by reference": a pointer to them is copied in the calls stack. The fact that this is a pointer is indicated by *
- the function can only "return" a single native type
- the function can also update memory locations to which a pointer has been passed, this is how extra return values can be used
In addition:
- Except for constructors, in the C description the first argument of a class method is an object of the class
- When used with Python object syntax, this first argument becomes the object on which the method is called (with of course, one less argument).
- So for instance the method described in the doc as do_something(SomeClass, arg1, arg2) is called in Python as instance_of_SomeClass.do_something(arg1,arg2)
For instance with this "C" prototype from the Gimp.Drawable description:
Code:
gboolean
gimp_drawable_get_offsets (
GimpDrawable* drawable,
gint* offset_x,
gint* offset_y
)
Where GimpDrawable is a "complex" type, and gboolean and gint are "native" type (just names for machine-size integers).
* the function returns a boolean
* the first argument is a pointer/reference to GimpDrawable. Since GimpDrawable is a complex type it is a simple "input" argument.
* as stated above, since this is a method on Gimp.Drawable in python it will be called on the object which is the first argument.
* offset_x and offset_y are references to native types, and so are outputs to the function. In Python your inputs are immutable, so this is converted to extra return values, and the method returns a tuple.
So this would be called as:
boolean_success, offset_x,offset_y= get_offsets(layer: Gimp.Drawable)
But since the first argument is of the type described, in Python this method call on a Gimp.Drawable object, so it is passed implicitly when calling the method.
boolean_success, offset_x,offset_y= layer.get_offsets()
The returned boolean here is a bit artificial. This is probably because the method has to use output arguments to return X and Y, so this is the only way to check that the memory locations passed for the offsets have been updated. This can still be ignored in the vast majority of cases by writing:
_, offset_x,offset_y= layer.get_offsets()
where _ is the Python convention to indicate that you don't really care about this value.
Slightly harder:
Code:
GimpLayer*
gimp_image_get_layer_by_name (
GimpImage* image,
const gchar* name
)
- The function takes a reference to a GimpImage, so in this case this is the implicit reference to the object on which the method is called.
- The function takes a reference to gchar. This isn't an output for a single char, this is a reference to an array of characterss (arrays and pointer are equivalent in C, an array is defined by the address of its first element). And an array of gchar is... a string. What also indicates that this is an input-only argument is the const modifier.
- The call returns a pointer to a GimpLayer, so in Python, a plain Gimp.Layer
So this defines a Gimp.Image method that would be type-hinted as:
def get_layer_by_name(name: str) -> Gimp.Layer
Raising the bar:
Code:
GimpLayer **
gimp_image_get_selected_layers (
GimpImage* image
)
Here the call return a pointer to a pointer to GimpLayer... this is really a pointer to an array of GimpLayer, so for Python just a list of Gimp.Layer. So this is just:
def get_selected_layers() -> list[Gimp.Layer]
Gotcha:
Note that some calls are defined as functions and not as object methods. For instance:
Code:
gboolean
gimp_file_save (
GimpRunMode run_mode,
GimpImage* image,
GFile* file,
GimpExportOptions* options
)
This is a plain function in the Gimp namespace that takes 4 explicit arguments.
|
|
|
gimp don't let me dock color tab above tabs right side |
Posted by: strongtower1 - 04-02-2025, 11:30 PM - Forum: Gimp 2.99 & Gimp 3.0
- Replies (2)
|
 |
Hi everyone , I'm using Gimp 3.0.2-1 ( converted to Photogimp) and happens that when the window shows up the software don't let me adjust the window vertically , so....I can't be able to see the options of the lower right side compared to photoshop I'm talking about the another layer, opacity tool, and others. I tried to edit the preferences of window but no results to adjust the window vertically to fit the screen and I can be able to see the lower tools and options. Any recommend will be highly appreciated, my profound thanks in advance.
|
|
|
|