It is currently Thu Jul 04, 2024 3:07 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Eager to learn to input text in python script (Solved)
PostPosted: Wed May 27, 2020 11:14 am  (#1) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Hi friends, I want to keep learning different method on python scripting, and believe me you guys have been excellent tutors. When I have asked question, you're been prompt to reply and I appreciate that.

I created a " Glossy Rounded Web Button script" from the website "Gtuts.com" (it's no longer on the web) you have to find it through Wayback Machine. I want to learn, how to input a Text into the script? I have learned how to create the script, "hello world", but I don't know how to create the text, with the "string, font, size, color" in the button script. I leave you with the script and I reserved a spot for the function. Thank you in advanced.

#!/usr/bin/env python

# following steps in Round Web 2.0 Button with a Metal Ring tutorial by Gtust.com found at link: https://web.archive.org/web/20090217010542/http://gtuts.com//web//round-web-20-button-with-a-metal-ring
# It Creates a 450 x 450 px Web 2.0 Button.


# author: Pocholo
# date: 5/27/20

# Comments directed to http://gimpchat.com

# Installation:
# This script should be placed in the user plugin folder

# Copyright (C)

#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by   
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.


from gimpfu import *

def create_glossy_round_button(imgSize):

   imgSize = 450
   pdb.gimp_context_push()
   
   #Create the background
   img = pdb.gimp_image_new(imgSize, imgSize, RGB)
   backLayer = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Background", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, backLayer, 0)
   pdb.gimp_edit_fill(backLayer, FILL_WHITE)
   
   #Create the button base layer
   buttonLayer = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Button", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, buttonLayer, 0)
   pdb.gimp_layer_add_alpha(buttonLayer)
   pdb.gimp_drawable_fill(buttonLayer, FILL_TRANSPARENT)
   
   #Apply first gradient
   pdb.gimp_context_set_foreground((255, 255, 255))
   pdb.gimp_context_set_background((44, 44, 44))
   pdb.gimp_image_select_ellipse(img, CHANNEL_OP_REPLACE, 25, 25, 400, 400)
   pdb.gimp_edit_blend(buttonLayer, 0,  LAYER_MODE_NORMAL, 2, 100, 20, 0, FALSE, TRUE, 3, 0.20, TRUE, 225, 25, 225, 425)
   
   #Create the button dropshadow
   pdb.script_fu_drop_shadow(img, buttonLayer, 0, 6, 15, (0, 0, 0), 80, TRUE)
   
   #Apply secon grafient
   pdb.gimp_selection_shrink(img, 35)
   pdb.gimp_edit_blend(buttonLayer, 0, LAYER_MODE_NORMAL, 2, 100, 20, 0, FALSE, TRUE, 3, 0.20, TRUE, 225, 390, 225, 60)
   
   #Create the inner sphere layer
   pdb.gimp_selection_shrink(img, 5)
   innersphereLayer = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Sphere", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, innersphereLayer, 0)
   pdb.gimp_layer_add_alpha(innersphereLayer)
   pdb.gimp_drawable_fill(innersphereLayer, FILL_TRANSPARENT)
   pdb.gimp_context_set_foreground((32, 110, 218))
   pdb.gimp_edit_fill(innersphereLayer, FILL_FOREGROUND)
   pdb.gimp_context_set_foreground((79, 238, 255))
   pdb.gimp_edit_blend(innersphereLayer, 2,  LAYER_MODE_NORMAL, 2, 100, 20, 0, FALSE, TRUE, 3, 0.20, TRUE, 225, 390, 225, 140)
   pdb.gimp_context_set_foreground((255, 255, 255))
   name = pdb.gimp_context_get_brush()
   pdb.gimp_context_set_brush("2. Hardness 050")
   pdb.gimp_context_set_brush_size(300)
   pdb.gimp_context_set_brush_aspect_ratio(0)
   pdb.gimp_context_set_brush_angle(0)
   pdb.gimp_paintbrush_default(innersphereLayer, 2, [225, 390])
   
   #Create an inner shadow on the innersphere
   pdb.gimp_selection_grow(img, 2)
   innershadowLayer = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Inner shadow", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, innershadowLayer, 0)
   pdb.gimp_layer_add_alpha(innershadowLayer)
   pdb.gimp_drawable_fill(innershadowLayer, FILL_TRANSPARENT)
   pdb.gimp_context_set_foreground((0, 0, 0))
   pdb.gimp_edit_fill(innershadowLayer, FILL_FOREGROUND)
   pdb.gimp_selection_feather(img, 20.000)
   pdb.gimp_edit_clear(innershadowLayer)
   pdb.gimp_selection_none(img)
         
   #Duplicate the inner shadow and merge down
   non_empty = pdb.gimp_edit_copy(innershadowLayer)
   innershadowcopy = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Planet copy", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, innershadowcopy, -1)
   pdb.gimp_layer_add_alpha(innershadowcopy)
   pdb.gimp_drawable_fill(innershadowcopy, FILL_TRANSPARENT)
   floating_sel = pdb.gimp_edit_paste(innershadowcopy, FALSE)
   pdb.gimp_floating_sel_anchor(floating_sel)
   planetcopy = pdb.gimp_image_merge_down(img, innershadowcopy, CLIP_TO_IMAGE)
   
   #Create the gloss
   glowLayer = pdb.gimp_layer_new(img, imgSize, imgSize, RGB, "Glow", 75, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, glowLayer, 0)
   pdb.gimp_layer_add_alpha(glowLayer)
   pdb.gimp_drawable_fill(glowLayer, FILL_TRANSPARENT)
   pdb.gimp_context_set_foreground((255, 255, 255))
   pdb.gimp_image_select_ellipse(img, CHANNEL_OP_REPLACE, 115, 67, 220, 125)
   pdb.gimp_edit_blend(glowLayer, 2, LAYER_MODE_NORMAL, 0, 100, 0, 0, FALSE, TRUE, 3, 0.20, TRUE, 225, 67, 225, 190)
   pdb.gimp_selection_none(img)
   
   #Reserve for font function
      
   
   pdb.gimp_display_new(img)
   
   pdb.gimp_context_pop()

   
register(
   "create_glossy_round_button",
   "Creates glossy round web button",
   "Creates glossy round web button",
   "Pocholo",
   "Pocholo",
   "2020",
   "Glossy button",
   "",
[
   (PF_ADJUSTMENT, "imgSize", "Image size", 450, (450, 800, 1)),
   
],
[],
create_glossy_round_button, menu="<Image>/Python-Fu/Glossy button")

main()

_________________
https://www.deviantart.com/pocholo17
Image


Last edited by Pocholo on Thu May 28, 2020 7:30 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Eager to learn to input text in python script
PostPosted: Wed May 27, 2020 4:14 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4756
Easy,

1) you need a PF_STRING parameter so that the user can input the text
2) you can use PF_FONT, and PF_INT/PF_SLIDER/PF_SPINNER parameter for the font and its size (or you can just use the ones in the Gimp context)
3) You can use a PF_COLOR to get the color (or you us the FG/BG color from the context)

Then you use
layer = pdb.gimp_text_layer_new(image, text, fontname, size, unit)

to create the layer (the color is taken from the FG color in the context)

_________________
Image


Top
 Post subject: Re: Eager to learn to input text in python script
PostPosted: Wed May 27, 2020 9:30 pm  (#3) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
Thank you ofnuts, it was very simple indeed. Somehow I had the idea, but I wanted to verify it and trust with what better that one of Gimpchat experience python script writer. I'm glad that you and the other script writer are part of Gimpchat. :coolthup

_________________
https://www.deviantart.com/pocholo17
Image


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Eager to learn how to draw pixel functions in GIMP python

2

No new posts Attachment(s) manipulate a portion of text inside a text layer using python-fu

2

No new posts Attachment(s) Learning to do first Python script

6

No new posts Attachment(s) My first Python Script for Gimp

7

No new posts .py script not showing under Python-Fu

3



* Login  



Powered by phpBB3 © phpBB Group