It is currently Sat Jun 22, 2024 5:49 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 19 posts ] 
Author Message
 Post subject: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Oct 26, 2023 8:33 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Breathing in one word, breathing out another word.
While I was visualizing a chant or words of a chant. I visualize a word as I breath in and visualize another word as I breath out.
So I wanted to animate this.
And here it is and example output:
Image

You just have a background image you want to create the text animation on, enter center x and y of where you want the text to appear, select font size and enter Phrase, it'll animate per words and then enter frames you want for inhaling and exhaling (default is 15 frames for inhaling and 20 frames for exhaling since exhaling usually takes longer) but it's totally up to you.
Plug-in uses current foreground color for text and current font.
The animation uses ease-in-out function so it accelerates toward halfway then decelerates to simulate breathing.
Plug-in code is below. Enjoy! :)
#!/usr/bin/env python
# bibo-text.py
# Created by TT
# This plug-in will accept a background layer, center-x, center-y and a sentence/phrase with multiple words separated by spaces.
# It will then animate by resizing the first word smaller and smaller then switches and resizes 2nd words larger and larger like as if you're breathing in and out.
#
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release

from gimpfu import *
import random


def ease_in_out(t):
    """Ease-in-out function: acceleration until halfway, then deceleration"""
    return 2*t*t if t < 0.5 else 1 - pow(-2*t + 2, 2) / 2
def python_bibo_text(image, layer, cx,cy,phrase,minsize,maxsize,framesin,framesex):
   # pdb.gimp_image_undo_group_start(image)
   # pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   framesin = int(framesin)
   framesex = int(framesex)
   words = phrase.split(" ")
   exhale = 0
   fontname = pdb.gimp_context_get_font()
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   for i in range(0,len(words)):
      word = words[i]
      if exhale == 0:
         frames = framesin
      else:
         frames = framesex   
      for j in range(0,frames):
         if exhale == 0:
            t = 1.0-float(j)/frames
         else:
            t = 0.0+float(j)/frames   
         size = minsize + (maxsize-minsize) * ease_in_out(t)
         opacity = 1.0 + (.2-1.0) * ease_in_out(t)
         text_layer = pdb.gimp_text_fontname(image,None,0,0,word,-1,TRUE,size,0,fontname)
         pdb.gimp_layer_set_offsets(text_layer,cx-text_layer.width/2,cy-text_layer.height/2)
         pdb.gimp_layer_set_opacity(text_layer,opacity * 100)
         new_layer = pdb.gimp_layer_new_from_visible(image,new_image,'frame')
         pdb.gimp_image_insert_layer(new_image,new_layer,None,0)
         pdb.gimp_image_remove_layer(image,text_layer)

      exhale = abs(exhale-1) #toggle between 0 and 1


   #YOUR CODE ENDS ========================
   # pdb.gimp_context_pop()
   # pdb.gimp_image_undo_group_end(image)
   
   pdb.gimp_displays_flush()

    #return

register(
   "python_fu_bibo_text",
   "Creates Bibo-text",
   "Creates Bibo-text",
   "TT",
   "TT",
   "October 26, 2023",
   "<Image>/Python-Fu/BIBO-text...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   (PF_INT, "cx", "Center-X:", 452),
   (PF_INT, "cy", "Center-Y:", 210),
   (PF_TEXT, "phrase", "Text Phrase:", "NAM MO A DI DA PHAT"),
   (PF_INT, "minsize", "Min Size:", 50),
   (PF_INT, "maxsize", "Max Size:", 150),
   (PF_INT, "framesin", "Frames Per Inhaling:", 15), #1.5 to 2 seconds
   (PF_INT, "framesout", "Frames Per Exhaling:", 20), #2 to 3 seconds.
   #INPUT ENDS
   ],
   [],
   python_bibo_text)

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.


See also
BIBO-layers in 4th post
BIBO-layers (Rel.2) in 8th post

_________________
TinT


Last edited by trandoductin on Sun Oct 29, 2023 3:05 am, edited 2 times 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: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Oct 26, 2023 9:02 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Another sample for fun
Image

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Fri Oct 27, 2023 12:15 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 785
Location: SEA - South East Asia
Nice! :clap
Is it possible, to add an options to do the same but with multiple layers (in a group for example or linked layers, or tagged layers)?

for example, one draw a circle on a layer, than a triangle on another one, then a square on a third one, and a star on a forth layer, and get the same effect with the drawing?

_________________
Patrice


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Fri Oct 27, 2023 8:40 am  (#4) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Thank you PixLab!
A great suggestion but I didn't mix it with the same plug-in since it expects slightly different parameters.
I call this one bibo-layers.py (code at the bottom of this post).
It takes [linked] layers and treat them like words, the size becomes min size (percentage) and max size (percentage).
What the plug-in does is it first reads all the linked layers and then hide them all (visiblility FALSE) so that it doesn't affect the layer it creates for animation.
Similar logics as the other bibo-text.py.

Here's a sample output from an image that has the mannequin as background image (not linked) and 4 other layers with differently drawn shapes (linked).
Image

Here's the code:
#!/usr/bin/env python
# bibo-layers.py
# Created by TT
# This plug-in suggested by PixLab http://gimpchat.com/viewtopic.php?f=9&t=20604&p=284691&sid=b619396ab8f6bdcd5b5ae3e759753e28#p284691
# Altered code from bibo-text.py to handle linked layers instead of creating text layers.
#
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release

from gimpfu import *
import random


def ease_in_out(t):
    """Ease-in-out function: acceleration until halfway, then deceleration"""
    return 2*t*t if t < 0.5 else 1 - pow(-2*t + 2, 2) / 2
def python_bibo_layers(image, layer, cx,cy,minsize,maxsize,framesin,framesex):
   # pdb.gimp_image_undo_group_start(image)
   # pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   framesin = int(framesin)
   framesex = int(framesex)
   exhale = 0
   fontname = pdb.gimp_context_get_font()
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   
   #get linked layers and reverse the order
   linkedlayers = []
   for l in image.layers:
      if pdb.gimp_item_get_linked(l) == TRUE:
         linkedlayers.append(l)
   linkedlayers.reverse()

   #hide all linked layers so it doesn't affect our animation layers
   for l in linkedlayers:
      pdb.gimp_item_set_visible(l,FALSE)

   for i in range(0,len(linkedlayers)):
      linkedlayer = linkedlayers[i]
      if exhale == 0:
         frames = framesin
      else:
         frames = framesex   
      for j in range(0,frames):
         if exhale == 0:
            t = 1.0-float(j)/frames
         else:
            t = 0.0+float(j)/frames   
         size = minsize + (maxsize-minsize) * ease_in_out(t)
         opacity = 1.0 + (.2-1.0) * ease_in_out(t)
         #text_layer = pdb.gimp_text_fontname(image,None,0,0,word,-1,TRUE,size,0,fontname)
         new_layer = pdb.gimp_layer_new_from_drawable(linkedlayer,image)
         pdb.gimp_image_insert_layer(image,new_layer,None,0)
         pdb.gimp_item_set_visible(new_layer,TRUE)
         
         #auto crop to make it layer to content
         pdb.plug_in_autocrop_layer(image,new_layer)

         #scale it based on size/percentage
         pdb.gimp_layer_scale(new_layer,new_layer.width*size/100.0,new_layer.height*size/100.0,TRUE)

         pdb.gimp_layer_set_offsets(new_layer,cx-new_layer.width/2,cy-new_layer.height/2)
         pdb.gimp_layer_set_opacity(new_layer,opacity * 100)
         visible_layer = pdb.gimp_layer_new_from_visible(image,new_image,'frame')
         pdb.gimp_image_insert_layer(new_image,visible_layer,None,0)
         pdb.gimp_image_remove_layer(image,new_layer)

      exhale = abs(exhale-1) #toggle between 0 and 1


   #YOUR CODE ENDS ========================
   # pdb.gimp_context_pop()
   # pdb.gimp_image_undo_group_end(image)
   
   pdb.gimp_displays_flush()

    #return

register(
   "python_fu_bibo_layers",
   "Creates Bibo-layers",
   "Creates Bibo-layers",
   "TT",
   "TT",
   "October 27, 2023",
   "<Image>/Python-Fu/BIBO-layers...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   (PF_INT, "cx", "Center-X:", 452),
   (PF_INT, "cy", "Center-Y:", 210),
   (PF_INT, "minsize", "Min Size %:", 10),
   (PF_INT, "maxsize", "Max Size %:", 100),
   (PF_INT, "framesin", "Frames Per Inhaling:", 15), #1.5 to 2 seconds
   (PF_INT, "framesout", "Frames Per Exhaling:", 20), #2 to 3 seconds.
   #INPUT ENDS
   ],
   [],
   python_bibo_layers)

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Fri Oct 27, 2023 9:35 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 785
Location: SEA - South East Asia
Wow, thank you Tran, very nice!
BTW I like your new Avatar :bigthup
Again thank you :tyspin

_________________
Patrice


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Fri Oct 27, 2023 10:14 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Thank you for the suggestion, it entertained me.

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sun Oct 29, 2023 1:07 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 785
Location: SEA - South East Asia
trandoductin wrote:
Thank you for the suggestion, it entertained me.

It's me who say :tyspin :bigthup

I'm gonna entertain you again :mrgreen:

On the original image after the script did run, it left my original changed, like the place of the drawn layers and one more layer on top, I stayed on Ctrl+Z to put back the drawn layers at their original place, but at one point no more history > I lose my history
Is it possible to fix it?
Attachment:
screenshot_20231029-130500.jpg
screenshot_20231029-130500.jpg [ 136.39 KiB | Viewed 1205 times ]


On the new image (generated), the draws have a different opacity/blending. if I understood that transparency is for when switching between 2 layers to be smooth, which is excellent :bigthup
Could it be possible to have an option to keep the same blending/opacity than the original image? (if not, don't mind it, that's already excellent ;) )
Attachment:
screenshot_20231029-130730.jpg
screenshot_20231029-130730.jpg [ 78.08 KiB | Viewed 1205 times ]


Last, by default it gives hard coordinates, is it possible to get the middle of the image by default?, if not, maybe an option to not move the layers?
Attachment:
screenshot_20231029-131715.jpg
screenshot_20231029-131715.jpg [ 69.96 KiB | Viewed 1205 times ]


Having said that, I like it a lot, I see possibilities animating people and other things, again thank you so much :tyspin
Especially with webp images ;)
Image

_________________
Patrice


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sun Oct 29, 2023 2:58 am  (#8) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
They are all great suggestions :)

1. It now saves the state of the visibilities of your linked layers, hide them all then do animation, then reload the states of visibilities at the end.
2. Added "Opacity Change:" toggle.
3. Added ""Move Layers To Given Center (x,y):" toggle.

Here's the options window now with 2 new toggles at bottom
Image

And here's the code for this Release 2:
#!/usr/bin/env python
# bibo-layers.py
# Created by TT
# This plug-in suggested by PixLab http://gimpchat.com/viewtopic.php?f=9&t=20604&p=284691&sid=b619396ab8f6bdcd5b5ae3e759753e28#p284691
# Altered code from bibo-text.py to handle linked layers instead of creating text layers.
#
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
# Rel 2: Leave the visibility unchanged of linked layers, added "Change Opacity" and "Move Layers" toggles as suggested by PixLab http://gimpchat.com/viewtopic.php?p=284716#p284716
from gimpfu import *
import random


def ease_in_out(t):
    """Ease-in-out function: acceleration until halfway, then deceleration"""
    return 2*t*t if t < 0.5 else 1 - pow(-2*t + 2, 2) / 2
def python_bibo_layers(image, layer, cx,cy,minsize,maxsize,framesin,framesex,opacitychange,movelayers):
   # pdb.gimp_image_undo_group_start(image)
   # pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   movelayers = int(movelayers)
   opacitychange=int(opacitychange)
   framesin = int(framesin)
   framesex = int(framesex)
   exhale = 0
   fontname = pdb.gimp_context_get_font()
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   
   #get linked layers and reverse the order
   linkedlayers = []
   visible = []
   for l in image.layers:
      if pdb.gimp_item_get_linked(l) == TRUE:
         linkedlayers.append(l)
         visible.append(pdb.gimp_item_get_visible(l))
   linkedlayers.reverse()
   visible.reverse()

   #hide all linked layers so it doesn't affect our animation layers
   for l in linkedlayers:
      pdb.gimp_item_set_visible(l,FALSE)

   for i in range(0,len(linkedlayers)):
      linkedlayer = linkedlayers[i]
      if exhale == 0:
         frames = framesin
      else:
         frames = framesex   
      for j in range(0,frames):
         if exhale == 0:
            t = 1.0-float(j)/frames
         else:
            t = 0.0+float(j)/frames   
         size = minsize + (maxsize-minsize) * ease_in_out(t)
         opacity = 1.0 + (.2-1.0) * ease_in_out(t)
         #text_layer = pdb.gimp_text_fontname(image,None,0,0,word,-1,TRUE,size,0,fontname)
         new_layer = pdb.gimp_layer_new_from_drawable(linkedlayer,image)
         pdb.gimp_image_insert_layer(image,new_layer,None,0)
         pdb.gimp_item_set_visible(new_layer,TRUE)
         
         #auto crop to make it layer to content
         pdb.plug_in_autocrop_layer(image,new_layer)

         #scale it based on size/percentage
         pdb.gimp_layer_scale(new_layer,new_layer.width*size/100.0,new_layer.height*size/100.0,TRUE)
         if (movelayers == 1):
            pdb.gimp_layer_set_offsets(new_layer,cx-new_layer.width/2,cy-new_layer.height/2)
         if (opacitychange == 1):
            pdb.gimp_layer_set_opacity(new_layer,opacity * 100)
         visible_layer = pdb.gimp_layer_new_from_visible(image,new_image,'frame')
         pdb.gimp_image_insert_layer(new_image,visible_layer,None,0)
         pdb.gimp_image_remove_layer(image,new_layer)

      exhale = abs(exhale-1) #toggle between 0 and 1

   #set it back to whatever visibility it was   
   for i in range(0,len(linkedlayers)):
      l = linkedlayers[i]
      v = visible[i]
      pdb.gimp_item_set_visible(l,v)
   #YOUR CODE ENDS ========================
   # pdb.gimp_context_pop()
   # pdb.gimp_image_undo_group_end(image)
   
   pdb.gimp_displays_flush()

    #return

register(
   "python_fu_bibo_layers",
   "Creates Bibo-layers",
   "Creates Bibo-layers",
   "TT",
   "TT",
   "October 27, 2023",
   "<Image>/Python-Fu/BIBO-layers...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   (PF_INT, "cx", "Center-X:", 452),
   (PF_INT, "cy", "Center-Y:", 210),
   (PF_INT, "minsize", "Min Size %:", 10),
   (PF_INT, "maxsize", "Max Size %:", 100),
   (PF_INT, "framesin", "Frames Per Inhaling:", 15), #1.5 to 2 seconds
   (PF_INT, "framesout", "Frames Per Exhaling:", 20), #2 to 3 seconds.
   (PF_TOGGLE, "opacitychange",   "Opacity Change:", 1),
   (PF_TOGGLE, "movelayers",   "Move Layers To Given Center (x,y):", 1),
   #INPUT ENDS
   ],
   [],
   python_bibo_layers)

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sun Oct 29, 2023 7:32 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 785
Location: SEA - South East Asia
Wonderful, not moving layers works like a charm thank you so much :tyspin

Image

_________________
Patrice


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sun Oct 29, 2023 9:00 am  (#10) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
You're welcome.
Release 2 is better now because of you. :D

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 1:46 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Maybe it's just me - but I would always prefer to change the layer when it is the smallest.


Attachments:
BiboLayers.gif
BiboLayers.gif [ 382.32 KiB | Viewed 1059 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 8:40 am  (#12) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
MareroQ, Thanks for your suggestion/preference:

"Word Per Breath" Toggle has been added.
Image

With it switched on/YES it looks like this:
Image

Here's the code
#!/usr/bin/env python
# bibo-text.py
# Created by TT
# This plug-in will accept a background layer, center-x, center-y and a sentence/phrase with multiple words separated by spaces.
# It will then animate by resizing the first word smaller and smaller then switches and resizes 2nd words larger and larger like as if you're breathing in and out.
#
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
# Rel 2: MareroQ on http://gimpchat.com/viewtopic.php?f=9&t=20604&start=10#p284795 prefers the word change when the text is small or when we just finished exhaling
#        so I added a "word per breath" toggle

from gimpfu import *
import random


def ease_in_out(t):
    """Ease-in-out function: acceleration until halfway, then deceleration"""
    return 2*t*t if t < 0.5 else 1 - pow(-2*t + 2, 2) / 2
def python_bibo_text(image, layer, cx,cy,phrase,minsize,maxsize,framesin,framesex,wordpb):
   # pdb.gimp_image_undo_group_start(image)
   # pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   
   wordpb = int(wordpb)
   framesin = int(framesin)
   framesex = int(framesex)
   words = phrase.split(" ")
   exhale = 1
   if (wordpb == 0):
      loop = len(words)
   else:
      loop = len(words)*2 #if word per breath we do twice the number of loop
   fontname = pdb.gimp_context_get_font()
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   for i in range(0,loop):
      if (wordpb == 0):
         word = words[i]
      else:
         word = words[int(i/2)];
      if exhale == 0:
         frames = framesin
      else:
         frames = framesex   
      for j in range(0,frames):
         if exhale == 0:
            t = 1.0-float(j)/frames
         else:
            t = 0.0+float(j)/frames   
         size = minsize + (maxsize-minsize) * ease_in_out(t)
         opacity = 1.0 + (.2-1.0) * ease_in_out(t)
         text_layer = pdb.gimp_text_fontname(image,None,0,0,word,-1,TRUE,size,0,fontname)
         pdb.gimp_layer_set_offsets(text_layer,cx-text_layer.width/2,cy-text_layer.height/2)
         pdb.gimp_layer_set_opacity(text_layer,opacity * 100)
         new_layer = pdb.gimp_layer_new_from_visible(image,new_image,'frame')
         pdb.gimp_image_insert_layer(new_image,new_layer,None,0)
         pdb.gimp_image_remove_layer(image,text_layer)
      exhale = abs(exhale-1) #toggle between 0 and 1


   #YOUR CODE ENDS ========================
   # pdb.gimp_context_pop()
   # pdb.gimp_image_undo_group_end(image)
   
   pdb.gimp_displays_flush()

    #return

register(
   "python_fu_bibo_text",
   "Creates Bibo-text",
   "Creates Bibo-text",
   "TT",
   "TT",
   "October 26, 2023",
   "<Image>/Python-Fu/BIBO-text...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   (PF_INT, "cx", "Center-X:", 452),
   (PF_INT, "cy", "Center-Y:", 210),
   (PF_TEXT, "phrase", "Text Phrase:", "NAM MO A DI DA PHAT"),
   (PF_INT, "minsize", "Min Size:", 50),
   (PF_INT, "maxsize", "Max Size:", 150),
   (PF_INT, "framesin", "Frames Per Inhaling:", 15), #1.5 to 2 seconds
   (PF_INT, "framesout", "Frames Per Exhaling:", 20), #2 to 3 seconds.
   (PF_TOGGLE, "wordpb",   "Word Per Breath:", 0), # initially True, checked.  Alias PF_BOOL
   #INPUT ENDS
   ],
   [],
   python_bibo_text)

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 11:01 am  (#13) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Thank you for the fast reponse.
I'll complain a little more:
- I was thinking about changing the BIBO layers (more universal - also the ability to change the text)
- Opacity switch (0 to 100 or 100 to 0)
- Centered option, not just offsets to x.y.
If you are busy with other things, ignore my whims.


Attachments:
BIBO-text-2 opacity is decreasing - I would like the option to increase it.gif
BIBO-text-2 opacity is decreasing - I would like the option to increase it.gif [ 1.46 MiB | Viewed 1034 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 12:35 pm  (#14) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Thanks for your recommended suggestions:
Image
Oh and "Use Image Center" Toggle
sample output:
Image

Here's the code this revision (3).
#!/usr/bin/env python
# bibo-text.py
# Created by TT
# This plug-in will accept a background layer, center-x, center-y and a sentence/phrase with multiple words separated by spaces.
# It will then animate by resizing the first word smaller and smaller then switches and resizes 2nd words larger and larger like as if you're breathing in and out.
#
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
# Rel 2: MareroQ on http://gimpchat.com/viewtopic.php?f=9&t=20604&start=10#p284795 prefers the word change when the text is small or when we just finished exhaling
#        so I added a "word per breath" toggle
# Rel 3: MareroQ on http://gimpchat.com/viewtopic.php?f=9&t=20604&p=284804#p284804 recommended ability to change start and end opacity
#        so I added these 2 input params
#        And ability to choose Use Image Center toggle
from gimpfu import *
import random


def ease_in_out(t):
    """Ease-in-out function: acceleration until halfway, then deceleration"""
    return 2*t*t if t < 0.5 else 1 - pow(-2*t + 2, 2) / 2
def python_bibo_text(image, layer, cx,cy,phrase,minsize,maxsize,framesin,framesex,wordpb,opastart,opaend,useimagecenter):
   # pdb.gimp_image_undo_group_start(image)
   # pdb.gimp_context_push()
   #YOUR CODE BEGINS=======================
   if (int(useimagecenter)==1):
      cx = image.width/2
      cy = image.height/2
   opastart = opastart/100.0
   opaend = opaend/100.0
   wordpb = int(wordpb)
   framesin = int(framesin)
   framesex = int(framesex)
   words = phrase.split(" ")
   exhale = 1
   if (wordpb == 0):
      loop = len(words)
   else:
      loop = len(words)*2 #if word per breath we do twice the number of loop
   fontname = pdb.gimp_context_get_font()
   new_image = pdb.gimp_image_new(image.width,image.height,RGB)
   pdb.gimp_display_new(new_image)
   for i in range(0,loop):
      if (wordpb == 0):
         word = words[i]
      else:
         word = words[int(i/2)];
      if exhale == 0:
         frames = framesin
      else:
         frames = framesex   
      for j in range(0,frames):
         if exhale == 0:
            t = 1.0-float(j)/frames
         else:
            t = 0.0+float(j)/frames   
         size = minsize + (maxsize-minsize) * ease_in_out(t)
         opacity = opaend + (opastart-opaend) * ease_in_out(t)
         text_layer = pdb.gimp_text_fontname(image,None,0,0,word,-1,TRUE,size,0,fontname)
         pdb.gimp_layer_set_offsets(text_layer,cx-text_layer.width/2,cy-text_layer.height/2)
         pdb.gimp_layer_set_opacity(text_layer,opacity * 100)
         new_layer = pdb.gimp_layer_new_from_visible(image,new_image,'frame')
         pdb.gimp_image_insert_layer(new_image,new_layer,None,0)
         pdb.gimp_image_remove_layer(image,text_layer)
      exhale = abs(exhale-1) #toggle between 0 and 1


   #YOUR CODE ENDS ========================
   # pdb.gimp_context_pop()
   # pdb.gimp_image_undo_group_end(image)
   
   pdb.gimp_displays_flush()

    #return

register(
   "python_fu_bibo_text",
   "Creates Bibo-text",
   "Creates Bibo-text",
   "TT",
   "TT",
   "October 26, 2023",
   "<Image>/Python-Fu/BIBO-text...",
   "*",      # Create a new image, don't work on an existing one
   [
   #INPUT BEGINS
   (PF_INT, "cx", "Center-X:", 452),
   (PF_INT, "cy", "Center-Y:", 210),
   (PF_TEXT, "phrase", "Text Phrase:", "NAM MO A DI DA PHAT"),
   (PF_INT, "minsize", "Min Size:", 50),
   (PF_INT, "maxsize", "Max Size:", 150),
   (PF_INT, "framesin", "Frames Per Inhaling:", 15), #1.5 to 2 seconds
   (PF_INT, "framesout", "Frames Per Exhaling:", 20), #2 to 3 seconds.
   (PF_TOGGLE, "wordpb",   "Word Per Breath:", 0), # initially True, checked.  Alias PF_BOOL
   (PF_INT, "opastart", "Opacity Start:", 0),
   (PF_INT, "opaend", "Opacity End:", 100),
   (PF_TOGGLE, "useimagecenter",   "Use Image Center", 0), # initially True, checked.  Alias PF_BOOL
   #INPUT ENDS
   ],
   [],
   python_bibo_text)

main()

# Below is all the example input types for INPUTS for the plug-in which can be cut and pasted into #INPUT BEGINS section and edited to taste
#           (PF_INT, "p0", "_INT:", 0), # PF_INT8, PF_INT16, PF_INT32  similar but no difference in Python.
#           (PF_FLOAT, "p02", "_FLOAT:", 3.141),
#           (PF_STRING, "p03", "_STRING:", "foo"),  # alias PF_VALUE
#           (PF_TEXT, "p04", "TEXT:", "bar"),
#           # PF_VALUE
#           # Pick one from set of choices
#           (PF_OPTION,"p1",   "OPTION:", 0, ["0th","1st","2nd"]), # initially 0th is choice
#           (PF_RADIO, "p16", "RADIO:", 0, (("0th", 1),("1st",0))), # note bool indicates initial setting of buttons
#           # PF_RADIO is usually called a radio button group.
#           # SLIDER, ADJUSTMENT types require the extra parameter of the form (min, max, step).
#           (PF_TOGGLE, "p2",   "TOGGLE:", 1), # initially True, checked.  Alias PF_BOOL
#           # PF_TOGGLE is usually called a checkbox.
#           (PF_SLIDER, "p3", "SLIDER:", 0, (0, 100, 10)),
#           (PF_SPINNER, "p4", "SPINNER:", 21, (1, 1000, 50)),  # alias PF_ADJUSTMENT
#           # Pickers ie combo boxes ie choosers from lists of existing Gimp objects
#           (PF_COLOR, "p14", "_COLOR:", (100, 21, 40) ), # extra param is RGB triple
#           # PF_COLOUR is an alias by aussie PyGimp author lol
#           (PF_IMAGE, "p15", "IMAGE:", None), # should be type gimp.image, but None works
#           (PF_FONT, "p17", "FONT:", 0),
#           (PF_FILE, "p18", "FILE:", 0),
#           (PF_BRUSH, "p19", "BRUSH:", 0),
#           (PF_PATTERN, "p20", "PATTERN:", 0),
#           (PF_GRADIENT, "p21", "GRADIENT:", 0),
#           (PF_PALETTE, "p22", "PALETTE:", 0),
#           (PF_LAYER, "p23", "LAYER:", None),
#           (PF_CHANNEL, "p24", "CHANNEL:", None),  # ??? Usually empty, I don't know why.
#           (PF_DRAWABLE, "p25", "DRAWABLE:", None),
#           # Mostly undocumented, but work
#           (PF_VECTORS, "p26", "VECTORS:", None),
#           (PF_FILENAME, "p27", "FILENAME:", 0),
#           (PF_DIRNAME, "p28", "DIRNAME:", 0)
#           # PF_REGION might work but probably of little use.  See gimpfu.py.

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 3:12 pm  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Thank You very much for quickly implementing my suggestions.


Attachments:
Bibo-Text Ver_3.gif
Bibo-Text Ver_3.gif [ 4.78 MiB | Viewed 1021 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Thu Nov 02, 2023 3:20 pm  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
hehe that's funny!

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sat Nov 04, 2023 12:27 pm  (#17) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
You can download (zip) also from:
https://www.gimpscripts.net/2023/11/bib ... h-out.html

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Sat Nov 04, 2023 3:37 pm  (#18) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3984
Location: Canada
Eh, thanks uploading it there. Cheers!

_________________
TinT


Top
 Post subject: Re: BIBO-text (Breath-in, Breath-out text)
PostPosted: Mon Nov 06, 2023 4:43 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: May 24, 2021
Posts: 785
Location: SEA - South East Asia
Thanks a lot Tin and Marek :tyspin

_________________
Patrice


Top
Post new topic Reply to topic  [ 19 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Lizard-Breath V.3

8

No new posts Attachment(s) GEGL Text Style Collection - plugin with many fancy text styles

14

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

2

No new posts script to load text file and create text layer

6

No new posts Attachment(s) GEGL ROCK TEXT 2 - Advance rock text plugin -requires Gimp 2.10.32+

8


cron

* Login  



Powered by phpBB3 © phpBB Group