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

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Adabelitoo
Regular
Posts: 61
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

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

#1 Post by Adabelitoo » Thu Aug 15, 2019 12:42 pm

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.

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

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

#2 Post by drKlauz » Thu Aug 15, 2019 12:55 pm

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".
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

User avatar
Adabelitoo
Regular
Posts: 61
Joined: Sat Apr 13, 2019 2:32 pm
Contact:

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

#3 Post by Adabelitoo » Thu Aug 15, 2019 10:10 pm

Were should I put that code? Do I have to just copy-paste it?

drKlauz
Veteran
Posts: 237
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

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

#4 Post by drKlauz » Thu Aug 15, 2019 10:56 pm

Can copy-paste in existing file, can save to init_images.rpy or something like and put it into game folder.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350


Post Reply

Who is online

Users browsing this forum: No registered users