Page 1 of 1

How to declare an image regardless its format? (PNG to WEBP)

Posted: Thu Aug 15, 2019 12:42 pm
by Adabelitoo
Before realising an update of my game I have to convert the .png image to .webp to save space. The problem is that when I work on it I need those image to be .png so I can see them as much as I need and while doing animations or showing a thumbnail of those image I will declare them like this

An animation:

Code: Select all

image el_001:
    "images/elly/elly_001.png"
    pause 0.1
    "images/elly/elly_002.png"
    pause 0.1
    "images/elly/elly_003.png"
    pause 0.1
    "images/elly/elly_002.png"
    pause 0.1
    repeat
A thumbnail of an image inside a gallery:

Code: Select all

image galb01_01:
    im.FactorScale("images/intro/b01_01.png",0.14)
But for the release I need to change those .png for .webp, and I know that I can always use Ctrl+F and replace them but I'm always afraid of changing something that I shouldn't and break the game. In the four updates my game had so far I forgot to change at least one of those .png to .webp in two updates.

My question is if it's possible to declare an image regardless of its file format.

Thanks for reading.

Re: How to declare an image regardless its format? (PNG to WEBP)

Posted: Thu Aug 15, 2019 12:55 pm
by drKlauz
I use this for automatic image declaration:

Code: Select all

python early:
  def scan_image_files():
    for fn in renpy.list_files():
      if '/' in fn:
        parts=fn.split('/')
      else:
        parts=[fn]
      if len(parts)>0 and parts[0] in ['images']:
        while len(parts)>0 and parts[0] in ['images','characters','locations']:
          parts.pop(0)
        if len(parts)>0 and parts[-1].endswith(('.png','.jpg','.webp')):
          parts[-1]=parts[-1].split('.')[0]
          renpy.image(' '.join(parts),fn)

  scan_image_files()
It allow reasonably folder structure with short file names.

Image "images/elly/elly_001.png" will be accessible by "elly elly_001" name. If you replace it with "images/elly/elly_001.webp" name will be same "elly elly_001".
In this case it is better to store images not as "images/elly/elly_001.png", but as "images/elly/001.png" or "images/characters/elly/001.png". In-game name will be "elly 001".

Re: How to declare an image regardless its format? (PNG to WEBP)

Posted: Thu Aug 15, 2019 10:10 pm
by Adabelitoo
Were should I put that code? Do I have to just copy-paste it?

Re: How to declare an image regardless its format? (PNG to WEBP)

Posted: Thu Aug 15, 2019 10:56 pm
by drKlauz
Can copy-paste in existing file, can save to init_images.rpy or something like and put it into game folder.

Re: How to declare an image regardless its format? (PNG to WEBP)

Posted: Thu Aug 15, 2019 11:20 pm
by Adabelitoo
Thanks!