GIMP Chat
http://gimpchat.com/

TypeError: could not convert to GimpRGB (Solved)
http://gimpchat.com/viewtopic.php?f=9&t=18319
Page 1 of 1

Author:  Pocholo [ Fri May 08, 2020 8:50 pm ]
Post subject:  TypeError: could not convert to GimpRGB (Solved)

Hi guy it's me again and I'm having trouble recognizing what I'm doing wrong in this script. :gaah
I know that fencepost created a Script-fu script that I used, but his script need it for you to install a scanline pattern.I just created a "Jean (denim) seamless pattern" strictly with no 3rd party add ons. I used the GIMP "Newsprint" plugin instead of a pattern to create the fabric like lines. OK, I'm getting "TypeError: could not convert to GimpRGB", what is this old senile guy :hehe missing?

File "C:\Users\Pocholo\AppData\Roaming\GIMP\2.10\plug-ins\Create a jean texture.py", line 43, in pm_jean__seamless_texture
pdb.gimp_context_set_foreground (fgColor)
TypeError: could not convert to GimpRGB




from gimpfu import *

def pm_jean__seamless_texture(size, fgColor):

   pdb.gimp_context_push()
   size = 500
   #Create the first blue layer
   img = pdb.gimp_image_new(size, size, RGB)
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Jean", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)
   
   #Create a new layer fill with Noise and change the layer mode
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Blue1", 100, LAYER_MODE_GRAIN_MERGE)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)
   pdb.plug_in_hsv_noise(img, layer, 1, 180, 0, 255)
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_GRAIN_MERGE)
   
   #Create a layer and change layer mode
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Blue2", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)   
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_GRAIN_MERGE)
   
   #Create a layer and create the texture
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Texture", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)   
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_MULTIPLY)
   pdb.plug_in_newsprint(img, layer,
                              6,
                              0,
                              0,
                              55,
                              1,
                              55,
                              1,
                              55,
                              1,
                              55,
                              1,
                              50)
   #Merge all layers
   layer = pdb.gimp_image_merge_visible_layers(img, CLIP_TO_BOTTOM_LAYER)
                              
   gimp.Display(img)
   
   pdb.gimp_context_pop()

Author:  Pocholo [ Fri May 08, 2020 9:18 pm ]
Post subject:  Re: TypeError: could not convert to GimpRGB

I had on the define line (size, fgColor) and the script was giving me an error mention above. I thought those were defined. I wrote on the lines below, the size = 500 and fgColor = (51, 112, 172). Now the script is running smoothly.

OK, I did't have to do this in the Heart script that I posted last night. What's the difference?



def pm_jean__seamless_texture(size, fgColor):

   pdb.gimp_context_push()
   
   size = 500
   fgColor = (51, 112, 172)
   
   #Create the first blue layer
   img = pdb.gimp_image_new(size, size, RGB)
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Jean", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)





This is the result

Image

Author:  MareroQ [ Fri May 08, 2020 10:53 pm ]
Post subject:  Re: TypeError: could not convert to GimpRGB

Hi Pocholo.

Congratulations. :clap
It works without error for me (after deleting the size = 500 entry and adding registration).
It would be easier to try if all the code was included.

Attachments:
Jenim by Pocholo.png
Jenim by Pocholo.png [ 26.21 KiB | Viewed 1643 times ]

Author:  Pocholo [ Fri May 08, 2020 11:23 pm ]
Post subject:  Re: TypeError: could not convert to GimpRGB

Thank you MareroQ. Can you explain me how you did it? I'm puzzle! :puzzled


from gimpfu import *

def pm_jean__seamless_texture(size, fgColor):

   pdb.gimp_context_push()
   
   size = 500
   fgColor = (51, 112, 172)
   
   #Create the first blue layer
   img = pdb.gimp_image_new(size, size, RGB)
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Jean", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)
   
   #Create a new layer fill with Noise and change the layer mode
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Blue1", 100, LAYER_MODE_GRAIN_MERGE)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)
   pdb.plug_in_hsv_noise(img, layer, 1, 180, 0, 255)
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_GRAIN_MERGE)
   
   #Create a layer and change layer mode
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Blue2", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)   
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_GRAIN_MERGE)
   
   #Create a layer and create the texture
   layer = pdb.gimp_layer_new(img, size, size, RGB, "Texture", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, layer, 0)
   pdb.gimp_context_set_foreground (fgColor)
   pdb.gimp_drawable_fill(layer, FILL_FOREGROUND)   
   pdb.gimp_layer_set_mode(layer, LAYER_MODE_MULTIPLY)
   pdb.plug_in_newsprint(img, layer,
                              6,
                              0,
                              0,
                              55,
                              1,
                              55,
                              1,
                              55,
                              1,
                              55,
                              1,
                              50)
   #Merge all layers
   layer = pdb.gimp_image_merge_visible_layers(img, CLIP_TO_BOTTOM_LAYER)
                              
   gimp.Display(img)
   
   pdb.gimp_context_pop()
   
   
   

register(
   "pm_jean__seamless_texture",
   "Creates a denim texture",
   "Creates a denim seamless texture",
   "Pocholo",
   "Pocholo",
   "2020",
   "Jean texture",
   "",

[
   
   (PF_COLOR, "fgcolor", "Texture color", (51, 112, 172)),
   (PF_SPINNER, "size", "Texture size", 500, (100, 1000, 1)),

],

[],
pm_jean__seamless_texture, menu="<Image>/Python-Fu/Jean texture")

main()   

Author:  MareroQ [ Sat May 09, 2020 12:33 am ]
Post subject:  Re: TypeError: could not convert to GimpRGB

You changed the order of PF_SPINNER, "size", with PF_COLOR, "fgcolor" (they must appear in the order in the definition), I removed unnecessary spaces in the registration (according to the attachment),
I commented on:
#size = 500
#fgColor = (51, 112, 172)

Do you use Notepad ++?

ps. Don't forget about #!/Usr/bin/env python.

Attachments:
P1 Error.png
P1 Error.png [ 8.37 KiB | Viewed 1629 times ]
P2 OK.png
P2 OK.png [ 7.68 KiB | Viewed 1629 times ]

Author:  Pocholo [ Sat May 09, 2020 1:01 am ]
Post subject:  Re: TypeError: could not convert to GimpRGB

Something so simple and yet for me a newbie, so hard. Thank you my friend owe you! Be safe. By the way, yes I use noterpad++.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/