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

Create a red heart script

Sun Apr 26, 2020 1:36 am

Here is my second GIMP script. It creates a nice shape heart with a light reflection. I wrote the script following the "Create an easy heart with GIMP 2.10" by conbagui found at link:http://fav.me/ddvrolq

Please expert coder, don't be so hard on me, I'm still in the baby learning process. Have good day and be safe!

Re: Create a red heart script

Sun Apr 26, 2020 2:45 am

The code is fine(*). But since there are no parameters, the script will always create the same image, so you might as well distribute the PNG :)

(*) Well, since you set the colors, you should bracket your code in gimp-context-push/gimp-context-pop call to leaves the premises in the state you found them.

Re: Create a red heart script

Sun Apr 26, 2020 2:48 am

Your script should have a
Code:
(script-fu-menu-register "script-fu-create-heart" "<Image>/File/Create")

Otherwise it won't register in GIMP 3.x
The script-fu register stuff should read like so, then:
Code:
(script-fu-register
    "script-fu-create-heart"                       
    "Create heart..."
    "Creates a heart shape image"   
    "Pocholo"                           
    "Pocholo"
    "April 2020"                         
    ""
)
(script-fu-menu-register "script-fu-create-heart" "<Image>/File/Create") 

Re: Create a red heart script

Sun Apr 26, 2020 7:34 am

@ ofnuts; Thank you for the info. I will try to create the image with parameters, but I need to learn how to do it. :tyspin

@nelo; Thanks, I will now register my script the way you did it or suppose to be done. :bigthup

Re: Create a red heart script

Tue Apr 28, 2020 11:55 pm

Ofnuts, Idon't know how can I create a parameter that make different sizes. So far I have this: SF-ADJUSTMENT "Layer Size (px)" '(500 50 1000 1 10 0 1). When the dialog pop out, I input a different size but I always get the same size 500 px. Thank you in advanced!

Re: Create a red heart script

Wed Apr 29, 2020 2:13 am

You need to use arguments in your function definition so that the dialog inputs are passed down to your code. These arguments do behave like variables that you can use instead of your hardcoded "500" value. Can't be more specific since i don't use Scheme.

Re: Create a red heart script

Wed Apr 29, 2020 2:33 am

@pocholo:
There is a small tutorial series on youtube by monsoonami
https://www.youtube.com/watch?v=dAuJJ6P ... 821B2370D4
maybe that helps. It did for me.

Re: Create a red heart script

Wed Apr 29, 2020 11:14 am

@nelo - Thank you for the link but somehow I'm not understanding how to create and adjustment that will make the image user's choice size.

@Ofnuts and nelo - Bear with me, please. I learned how to make the Background and the Heart to change colors. The only thing I need, is to able to create an SF-ADJUSTMENT to make the heart in different sizes. I created the adjustment Height and Width. When I change the width and the height on the dialog box, the layer resize, but the image of the heart don't.


Code:
; following steps in Create an easy heart with GIMP 2.10 by conbagui found at link:http://fav.me/ddvrolq
; author: Pocholo
; date: 4/25/20

; Comments directed to http://gimpchat.com

; Installation:
; This script should be placed in the user script 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/>.   







(define (script-fu-create-heart imgWidth imgHeight foreground-color heart-color)
    (let* (
       
      
      (img  (car (gimp-image-new imgWidth imgHeight RGB)))
        (layer (car (gimp-layer-new img imgWidth imgHeight RGB-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
      (theheart (car (gimp-layer-new img imgWidth imgHeight RGB "Heart" 100 LAYER-MODE-NORMAL)))
      (heartcopy 0)
      (heart 0)
      (theshadow (car (gimp-layer-new img imgWidth imgHeight RGB "Inner shadow" 100 LAYER-MODE-NORMAL)))
      (thereflection (car (gimp-layer-new img imgWidth imgHeight RGB "Reflection" 100 LAYER-MODE-NORMAL)))
      
      )

            
      ;Create the Background
        (gimp-image-undo-disable img)              ; Disable undo during the image creation
        (gimp-image-insert-layer img layer 0 0)
      (gimp-context-set-foreground foreground-color)
      (gimp-drawable-fill layer FILL-FOREGROUND)
      
      ;Create the heart layer
      (gimp-image-add-layer img theheart -1)
      (gimp-layer-add-alpha theheart)
      (gimp-drawable-fill theheart FILL-TRANSPARENT)
      
      ;Create the the first half of the heart
      (gimp-image-select-ellipse img  2 60 105 385 285)
      (gimp-image-select-rectangle img  1  0  0  500  250)
      (gimp-image-select-ellipse img  0 60 125 385  250)
      (gimp-context-set-foreground heart-color)
      (gimp-drawable-edit-fill theheart FILL-FOREGROUND)
      (gimp-selection-none img)
      (gimp-drawable-transform-rotate theheart 44.75 TRUE 250 250 0 2 TRUE 1 0)
      (gimp-layer-resize-to-image-size theheart)
      (gimp-image-select-rectangle img  2  250  0  250  500)
      (gimp-edit-cut theheart)
      (gimp-selection-none img)
      
      ;Create the second half of the heart
      (set! heartcopy (car (gimp-layer-copy theheart TRUE)))
      (gimp-image-add-layer img heartcopy -1)
      (gimp-item-transform-flip-simple heartcopy 0 1 0)
      (gimp-image-merge-down img heartcopy 1)
      
      ;Create a selection
      (set! heartcopy (car (gimp-image-get-active-drawable img)))
      (gimp-image-select-color img CHANNEL-OP-REPLACE  heartcopy heart-color)
      
      
      ;Create inner shadow layer
      (gimp-image-add-layer img theshadow -1)
      (gimp-layer-add-alpha theshadow)
      (gimp-drawable-fill theshadow FILL-TRANSPARENT)

      ;Shrink the selection and set the foreground color
      (gimp-selection-shrink img 8)
      (gimp-context-set-foreground '(0 0 0))
      
      ;Set the brush and the size apply
      (gimp-context-set-brush "2. Hardness 100")
      (gimp-context-get-brush)
      (gimp-context-set-brush-size 8)
      
      ;Stroke selection and apply gaussian blur
      (gimp-edit-stroke theshadow)
      (gimp-selection-none img)
      (plug-in-gauss RUN-NONINTERACTIVE  img theshadow 48 48 1)
      
      ;Create the light reflection on the heart
      
      ;Create light reflection layer
      (gimp-image-add-layer img thereflection 0)
      (gimp-layer-add-alpha thereflection)
      (gimp-drawable-fill thereflection FILL-TRANSPARENT)
      
      ;Draw the dot on the left side and apply gaussian blur
      (gimp-image-select-ellipse img  2 150 150 25 25)
      (gimp-edit-fill thereflection 2)
      (gimp-selection-none img)
      
      ;Merge the top two layer
      (plug-in-gauss RUN-NONINTERACTIVE img thereflection 18 18 1)
      (gimp-image-merge-down img thereflection 1)
      (set! theshadow (car (gimp-image-get-active-drawable img)))
      (gimp-image-merge-down img theshadow 1)   
      (gimp-display-new img)
      
      
      
      
   
      
      
      
      
   )
)




(script-fu-register
    "script-fu-create-heart"                       
    "Create a heart"
    "Creates a heart shape image"   
    "Pocholo"                           
    "Pocholo"
    "April 2020"                         
    ""

   SF-ADJUSTMENT "Image Height" '(500 50 1000 1 10 0 1)
   SF-ADJUSTMENT "Image Width" '(500 50 1000 1 10 0 1)
   SF-COLOR      "Foreground color"   "Black"
   SF-COLOR      "Heart color"   "Red"

)
(script-fu-menu-register "script-fu-create-heart" "<Image>/File/Create")

Re: Create a red heart script

Thu Apr 30, 2020 2:48 am

Most explicit numbers in your script should be replaced by imgWidth, imgHeight or some computation from these (for instance (/ imgWidth 2) or (/ imgHeight 2) instead of 250).

Re: Create a red heart script

Thu Apr 30, 2020 12:45 pm

There will be quite a lot of maths necessary, I guess.To see the problem you could:
disable this undo line in your script:
Code:
(gimp-image-undo-disable img)

Save it, refresh it.
Then run it once with the 500px size and a second time with say 800. Leave both open, so you can compare the steps it takes.
Now, having undo enabled you can go through your script step by step using the journal and see where the differences are.
You'll probably have to recalculate sizes and positions of your forms.

Hope these ideas help
nelo

Re: Create a red heart script

Sun May 03, 2020 2:09 pm

Still thinkin about this ... how it could be done fairly quick:

What if you just keep your 500px settings to work with and at the end scale the image like so:

Code:
      ; scale image
      (gimp-context-set-interpolation INTERPOLATION-NOHALO) ;The interpolation type { INTERPOLATION-NONE (0), INTERPOLATION-LINEAR (1), INTERPOLATION-CUBIC (2), INTERPOLATION-NOHALO (3), INTERPOLATION-LOHALO (4) }
      (gimp-image-scale img imgWidth imgHeight)


Next thought with this would be to just set only one value for width and height so you'll always have something square.


Edit:
better way: using a scaling factor as attached. Hopefully I didn't oversee stuff, but you'll get the idea.

Re: Create a red heart script

Sun May 03, 2020 3:47 pm

That is what I'm trying to learn and to do , nelo :jumpclap :clap . Thank you so much

Ok, can you explain a little about the "scaling factor", please?

Re: Create a red heart script

Mon May 04, 2020 2:05 am

The scaling factor is just some maths:
As all the tutorial was written for a fixed width/height of 500 I need a factor to convert everything for say 800px or 750px or whatever the user enters.
So I took the new value divided by the 500 to have a factor for multiplying all the values.
As you can see in the script I introduced the variable "scaled" like so
Code:
(scaled (/ imgSize 500))

I can then use it to convert all the fixed withs, heights and positions.
That's why I then have a lot of those
Code:
(* scaled 500)

in the script instead of just "500"

Re: Create a red heart script

Mon May 04, 2020 2:08 am

nelo wrote:Still thinkin about this ... how it could be done fairly quick:

What if you just keep your 500px settings to work with and at the end scale the image like so:

Code:
      ; scale image
      (gimp-context-set-interpolation INTERPOLATION-NOHALO) ;The interpolation type { INTERPOLATION-NONE (0), INTERPOLATION-LINEAR (1), INTERPOLATION-CUBIC (2), INTERPOLATION-NOHALO (3), INTERPOLATION-LOHALO (4) }
      (gimp-image-scale img imgWidth imgHeight)


Next thought with this would be to just set only one value for width and height so you'll always have something square.


Edit:
better way: using a scaling factor as attached. Hopefully I didn't oversee stuff, but you'll get the idea.


IMHO a wrong solution. Above 700px the image will be blurry. Creating a heart at the right size isn't difficult. If Pocholo want to learn how to program that would be definitely the wrong thing to do (but then starting with Scheme was also the wrong thing to do IMHO).

Re: Create a red heart script

Mon May 04, 2020 12:32 pm

Thank you guys for the explanations and the tips. I'm learning a lot from you, thank you! :yes

Now, I know you guys take your time to answer questions here in GC and I well appreciated.

I have another question; How to integrate G'MIC in a script-fu? I'm trying to create a "Orange peel pattern" script and so far I'm learning how to place the functions in the script. I'm not getting any errors, but I get the image with no result. What am I missing here?

I suppose to get this result

Image


But getting this

Image




Code:
(define (orange-peel-pattern)
    (let* (
   
      (imgWidth 500)
      (imgHeight 500)
          
            
      (img  (car (gimp-image-new imgWidth imgHeight RGB)))
      (layer (car (gimp-layer-new img imgWidth imgHeight RGB-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
       
      )
    
      (gimp-context-push)
      
      ; Begin Undo Group
      (gimp-image-undo-group-start img)
    
      ;Create the Background
      (gimp-image-insert-layer img layer 0 0)
      (gimp-context-set-foreground '(241 152 56))
      (gimp-drawable-fill layer FILL-FOREGROUND)
          
      ;Create the orange peel
      (plug-in-hsv-noise  RUN-NONINTERACTIVE img layer 8 3 4 150)    
      (plug-in-gmic-qt 1 img layer 0 0 "fx_relief_light 0.1  0, 0, 0, 0.3, 0, 0, 0, 0.03, 0, 0.3")
    
    
           
      (gimp-display-new img)
   
   
      ;End Undo Group
      (gimp-image-undo-group-end img)

      (gimp-displays-flush)

      ;Resets previous user settings
      (gimp-context-pop)
         

Re: Create a red heart script

Mon May 04, 2020 2:12 pm

Not sure ...
My version of GMIC says there is no "fx_relief_light" ... but I have a function called "fx_light_relief".
Maybe changing that helps?

Re: Create a red heart script

Mon May 04, 2020 2:43 pm

My version is "Relief Light", that is weird. I changed it to "light_relief" and still the same result. I want the same result as the Preview window is showing.

Image
Post a reply