Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

How to make plugin run faster

Thu Jun 18, 2020 8:43 pm

Hi guys, I hope everything is fine with all. I made a text effect python script using LayerFx.py filters but the script runs on about 30 seconds on a 100 px size text. Is there any way to make this script faster? Thanks in advanced and be safe!

Re: How to make plugin run faster

Fri Jun 19, 2020 12:06 am

Hi Pocholo.

Only small suggestions.
It may not be the easiest solution, but try to find the right piece of code in the layerfx.py file, analyze it and use (paste) in the new code. Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code). The adaptation will also have the advantage that it will work for users who do not have the layerfx.py file installed.

Re: How to make plugin run faster

Fri Jun 19, 2020 1:54 am

If you tell us what you are trying to achieve, we may be able to suggest a quicker way of doing it.

Kevin

Re: How to make plugin run faster

Fri Jun 19, 2020 2:51 am

Post the bloody code already. :)

Re: How to make plugin run faster

Fri Jun 19, 2020 4:05 am

MareroQ wrote:Hi Pocholo.

... Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code)....


...I'm sure that -if Ofnuts will spend a bit of his summer vacation on this subject- his python version of layerfx would be less of 1000 lines of code.

Re: How to make plugin run faster

Fri Jun 19, 2020 4:22 am

dinasset wrote:
MareroQ wrote:Hi Pocholo.

... Layerfx.py contains about 6570 lines of code, but a significant part is related only to the preview function (using gtk, which slows down the execution). It is possible that it will be easier to parse the layerfx.scm code (this is only about 1485 lines of code)....


...I'm sure that -if Ofnuts will spend a bit of his summer vacation on this subject- his python version of layerfx would be less of 1000 lines of code.


Yes, but nobody would understand how to use it :)

Re: How to make plugin run faster

Fri Jun 19, 2020 5:32 am

Now why would anyone think that ;)

fx.jpg
fx.jpg (170.84 KiB) Viewed 7391 times

Re: How to make plugin run faster

Fri Jun 19, 2020 7:02 am

Rich, you forgot (requires at least two paths for it to run and you know where they go, figure it out).

Re: How to make plugin run faster

Fri Jun 19, 2020 7:05 am

rich2005 wrote:Now why would anyone think that ;)

fx.jpg


Node-based editing at its finest :) And if you draw a chicken you get your text as rolling 3D credits, Star-wars style.

Re: How to make plugin run faster

Fri Jun 19, 2020 7:09 am

ofnuts wrote:
rich2005 wrote:Now why would anyone think that ;)

fx.jpg


Node-based editing at its finest :) And if you draw a chicken you get your text as rolling 3D credits, Star-wars style.


Now I'm going to open all of your files and check for Easter eggs.

Re: How to make plugin run faster

Fri Jun 19, 2020 7:50 am

Thank you for your quick responds, here is the code:

Code:
#!/usr/bin/env python

# author: Pocholo
# date: 6/6/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 pm_incredible_hulk_text(customtext, font, fontsize, textcolor):

   
   #Create image
   img = pdb.gimp_image_new(1, 1, RGB_IMAGE)
   
   pdb.gimp_context_push()
   
   #Create the text
   pdb.gimp_context_set_foreground(textcolor)
   layer = pdb.gimp_text_fontname(img, None, 0, 0, customtext, 65,
                              TRUE, fontsize, PIXELS, font)
   pdb.gimp_text_layer_set_letter_spacing(layer, 30)
   pdb.gimp_text_layer_set_justification(layer, 2)
         
   #Resize image
   img.resize(layer.width, layer.height, 0, 0)
   
   #Create background
   backlayer = pdb.gimp_layer_new(img, layer.width, layer.height, RGB_IMAGE, "Background", 100, LAYER_MODE_NORMAL)
   pdb.gimp_image_add_layer(img, backlayer, 1)
   pdb.gimp_context_set_gradient("Greens")
   pdb.gimp_drawable_edit_gradient_fill(backlayer, 0, 0, TRUE, 3, 0.20, TRUE, 800, 0, 800, 900)
   
   
   #Text drop shadow
   pdb.python_layerfx_drop_shadow(img, layer,
                           (0, 0, 0),   #color
                                0.75,   #opacity
                                  1,   #contou
                                  0,   #noise
                                  3,   #mode for multiply
                                 15,   #spread
                                 20,   #size
                                 120,   #offset_angle
                                 20,   #offset_distance
                                TRUE,   #knockout
                               FALSE)   #merge
   
      
   #Text inner shadow
   pdb.python_layerfx_inner_shadow(img, layer,
                            (0, 0, 0),   #color
                                   75,   #opacity
                                   1,   #contou
                                   0,   #noise
                                   3,   #mode for multiply
                                   1,   #source
                                   0,   #choke
                                   45,   #size
                                 120,   #offset_angle
                                   5,   #offset_distance
                                 FALSE)  #merge
   
      
   #Text outer glow
   pdb.python_layerfx_outer_glow(img, layer,
                           (14, 34, 0),   #color
                                 100,   #opacity
                                   0,   #contou
                                   0,   #noise
                                   4,   #mode
                                    8,   #spread
                                  14,   #size
                                 TRUE,   #knockout
                                FALSE)   #merge   
   
   
   pdb.python_layerfx_bevel_emboss(img, layer,
                                    1,   #style inner bevel
                                    65,   #depth
                                     0,   #direction
                                    48,   #size
                                    4,   #soften
                                   120,   #angle
                                    65,   #altitude
                                    5,   #gloss_contour
                                "White",   #highlight_color
                                    10,   #highlight_mode lighten only
                                    40,   #highlight_opacity
                                "Black",   #shadow_color
                                    17,   #shadow_mode burn
                                    55,   #shadow_opacity
                                     6,   #surface_contour
                                  TRUE,   #use_texture
                            "Dried mud",   #pattern
                                   150,   #scale
                                   -30,   #tex_depth
                                  TRUE,   #invert
                                 FALSE)   #merge   
   
      
   pdb.python_layerfx_satin(img, layer,
                      (27, 92, 26),   #color
                               90,   #opacity
                               3,   #mode MULTIPLY
                              19,   #offset_angle
                              14,   #offset_distance
                               60,   #size
                                3,   #contou
                             TRUE,   #invert
                            FALSE)   #merge   
   
   
   pdb.python_layerfx_color_overlay(img, layer,
                              (44, 63, 2),   #color
                                    100,   #opacity
                                     18,   #mode hard light   
                                   FALSE)   #merge
   
   
   pdb.gimp_context_set_foreground((0, 255, 0))
   pdb.gimp_context_set_background((255, 255, 255))
   pdb.python_layerfx_gradient_overlay(img, layer,
                            "FG to BG (RGB)",   #gradient
                                        0,   #gradient_type linear
                                        0,   #repeat none
                                     FALSE,   #reverse
                                       85,   #opacity
                                       21,   #mode grain merge
                                        0,   #center_x
                                        0,   #center_y
                                       90,   #angle
                                       200,   #width
                                     FALSE)   #merge
   
         
   pdb.python_layerfx_pattern_overlay(img, layer,
                                "Dried mud",   #pattern
                                      100,   #opacity
                                        21,   #mode grain merge
                                      150,   #scale
                                       0,   #interpolation
                                    FALSE)   #merge
   
      
   gimp.Display(img)
   pdb.gimp_context_pop()
   
      
   
register(
   "pm_incredible_hulk_text",
   "Creates a muscles text",
   "Creates a Hulk text",
   "Pocholo",
   "Pocholo",
   "2020",
   "The incredible Hulk text",
   "",
[
   (PF_STRING, "customtext", "Text string", 'HULK'),
    (PF_FONT, "font", "Font face", "Berlin Sans FB Bold"),
   (PF_SPINNER, "fontsize", "Font size", 300, (100, 500, 1)),
   (PF_COLOR, "textcolor", "Text color", (1, 48, 1)),
],
[],
pm_incredible_hulk_text, menu="<Image>/Python-Fu/The incredible Hulk text")
main()

Re: How to make plugin run faster

Fri Jun 19, 2020 8:50 am

Since you are working on a new image, you can disable undo: pdb.gimp_image_undo_disable(image)/pdb.gimp_image_undo_enable(image).

Otherwise since you are mostly calling LayerFX functions, either you find a way to obtain the same results without piling up effects, or you look at the LayerFx code and steal the relevant bits.

Re: How to make plugin run faster

Wed Aug 12, 2020 7:23 am

Hi Pocholo.

I quickly needed such an effect so I added the Filters / Alpha to Logo / Hulk efect by Pocholo option ...
You didn't add a download package - so I add.
I hope you won't be offended by the attention: maybe you will add this option to your other plugins?

The speed of execution is acceptable - I know much slower ones.

Re: How to make plugin run faster

Wed Aug 12, 2020 8:00 am

No a problem my friend. I'm rather flatter by using my script to improve it. Thanks :) :hi5
Post a reply