It is currently 20 May 2022, 07:39

• Featuring Members' Images •
Could be related to 'Palette from Image (aka Palette Importer) Script/Plug-in'
skinnyhouse
tim
skinnyhouse
tim
tim

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

Palette from Image (aka Palette Importer) Script/Plug-in

Share your Python Fu Scripts/plug-ins for GIMP here
tim
GL Blogger
1st Place
5822 Post(s)

Palette from Image (aka Palette Importer) Script/Plug-in

Post#1 by tim » 23 Jul 2018, 14:56


Palette from Image Script or Plug-in banner/
Trying to help/answer this question on reddit: Confused with palettes.
So you've got an neat (as in evenly distributed columns and rows) image of palette colors.
You just want to create a palette from the image of colors.
You want to generally read the middle pixel of each tile in your image into a color palette so that it'll have the same order as your image.
I guess this script/plug-in can be used as a palette importer from screenshots of a palette shown in other programs.
If you're interested in importing a palette from a file that was exported by GIMP, you might be interested in the Import Palette from File Script/Plug-in

Here's a script that'll help with that.
palette_from_image.zip #
zipped .py file (unzip, put in your GIMP's /plug-ins/ folder) (Tested in GIMP 2.8 and 2.10)
(1.26 KiB) Downloaded 322 times
Script Menu Location: Python-Fu/Palette from Image...

Instructions:
  1. Open your image of evenly distributed columns and rows of colors in GIMP
  2. Run script (Python-Fu/Palette from Image...), Enter a palette name to create with, Select number of columns in your image (default 16), select number of rows in your image (default 16). Click "OK" to run script.
  3. A new palette will be created with the name you've entered.

    Script Options:
    palette_from_image_options.png
    palette_from_image_options.png # (31.21 KiB) Viewed 3297 times Thumbnail
    Sample run:
    palette.png
    Input image to run script on with 16 columns 16 rows
    palette.png # (2.93 KiB) Viewed 3297 times Thumbnail
    Palette_from_image_result_palette.png
    resulting palette from script
    Palette_from_image_result_palette.png # (24.14 KiB) Viewed 3297 times Thumbnail
aka Tin
World Food Program | Good Deeds Forum

         

tim
GL Blogger
1st Place
5822 Post(s)

Post#2 by tim » 26 Jul 2018, 21:03


for some reason reddit OP/user of the mentioned question can't get script to work.
So here's a work around
Open up the palette image input like above in GIMP make sure it's the only image opened (with only one layer).
Then go to Filters>Python-Fu>Console
and paste the below code into the Console and press Enter

Code: Select all

def tt_test1(image, layer, palette_name,hor_colors, vert_colors ):
	column_width = layer.width / hor_colors;
	row_height = layer.height / vert_colors;
	mid_offset_x = column_width / 2.0; #offset it so that we generally get the middle pixel.
	mid_offset_y = row_height / 2.0; #offset it so that we generally get the middle pixel.
	actual_name = pdb.gimp_palette_new(palette_name)
	for iy in range(0,int(vert_colors)):
		y = iy * row_height + mid_offset_y;
		for ix in range(0,int(hor_colors)):
			x = ix * column_width + mid_offset_x;
			num_channels,pixel = pdb.gimp_drawable_get_pixel(layer,x,y)
			pdb.gimp_palette_add_entry(actual_name,"Color " + str(iy*16+ix+1),pixel[0:3])

image = gimp.image_list()[0]
layer = pdb.gimp_image_get_active_layer(image)
tt_test1(image,layer,"a test one",16,16)
This will create a palette named "a test one" based on the 16x16 palette image.
You can optionally change the options in the last line of the code where it calls the tt_test1 function.
aka Tin
World Food Program | Good Deeds Forum

         


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 New Topic
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 21 guests