need help making a gallery

juls0

Newbie
Oct 19, 2019
19
5
I am a newbie to all this. I barely know python language and i'm barely advancing with my project little by little. I am trying to set up a gallery for a project but no tutorial, video, or script works for me. I get errors such as "cannot find image.png" or "not displayable" or something. I have my own test cgs (stick figures in colored backgrounds in 1920x1080). The best i have is this:
Code:
# defining sample images
init:
    image cg1 = "ch1_cg1.png"
    image cg2 = "ch1_cg1.png"
    image cg3 = "ch1_cg3.png"
    image cg4 = "ch2_cg1.png"
    image cg5 = "ch2_cg2.png"
    image cg6 = "ch2_cg3.png"
    image cg7 = "ch3_cg1.png"
    image cg8 = "ch3_cg2.png"
    image cg9 =  "ch3_cg3.png"
    image cg10 = "extracg1.png"
    image cg11 = "extracg2.png"
    image cg12 = "extracg3.png"

# defining gallery
init python:
    g = Gallery()

    g.button("cg1")
    g.unlock_image("ch1_cg1")

    g.button("cg2")
    g.unlock_image("ch1_cg2")

    g.button("cg3")
    g.unlock_image("cgh!_cg3")

    g.transition = dissolve

screen gallery():
    default gallery_page = 1
    tag menu
    add "gui/gallery_bg.jpg"

    $ gallery_char_column_max = 3
    $ gallery_char_row_max = 2

    $ gallery_max_chars_per_page = gallery_char_column_max * gallery_char_row_max

    vbox:
        # ("cg number, file name without png/jpg extension)
        add g.make_button("cg1", "ch1_cg1", xalign=0.5, yalign=0.5 )
        add g.make_button("cg2", "ch1_cg2", xalign=0.5, yalign=0.5 )
        add g.make_button("cg3", "ch1_cg2", xalign=0.5, yalign=0.5 )

    textbutton "Return" action Return() xalign 0.5 yalign 0.9
what this does is that it displays the first image in full screen. At least the return button works.
Capture.PNG
I try to look up tutorials but they all use code that looks nothing like each other. If i try to copy paste other codes for thumbnails i just get errors, even after renaming the files with my pictures.
Visiting the renpy library doesnt help either

What i want to do is have a gallery for characters scenes. Like a screen with "characters a b or c" that takes you to their gallery for their scenes.
I am really starting to lose hope since a gallery is basically mandatory for a visual novel.
 

juls0

Newbie
Oct 19, 2019
19
5
thank you. That sort of works. But now i need to change the name files to my own and for some reason the game show an error "cannot find image.png"

I am having that problem with other codes too. The gallery shows up nice if i dont change a thing but the problem now is putting the images in.

i am using this now:

Code:
# defining sample images
init:
    image cg1 = "ch1_cg1.png"
    image cg2 = "ch1_cg1.png"
    image cg3 = "ch1_cg3.png"
    image cg4 = "ch2_cg1.png"
    image cg5 = "ch2_cg2.png"
    image cg6 = "ch2_cg3.png"
    image cg7 = "ch3_cg1.png"
    image cg8 = "ch3_cg2.png"
    image cg9 =  "ch3_cg3.png"
    image cg10 = "extracg1.png"
    image cg11 = "extracg2.png"
    image cg12 = "extracg3.png"

init python:
    def gallery_thumbnail(thumbnail_name):
        return im.FactorScale(thumbnail_name, 0.2)

    image_gallery = Gallery()
    image_gallery.transition = dissolve
    image_gallery.locked_button = "gallery_locked_button"

    image_gallery.button("slot01")
    image_gallery.condition('renpy.seen_image("ch0b_12")')
    image_gallery.unlock_image("ch0b_09")
    image_gallery.unlock_image("ch0b_10")
    image_gallery.unlock_image("ch0b_11_movie")
    image_gallery.unlock_image("ch0b_12")

    image_gallery.button("slot02")
    image_gallery.condition('renpy.seen_image("ch0d_27")')
    image_gallery.unlock_image("ch0d_24")
    image_gallery.unlock_image("ch0d_25")
    image_gallery.unlock_image("ch0d_26_movie")
    image_gallery.unlock_image("ch0d_27")

    image_gallery.button("slot03")
    image_gallery.condition('renpy.seen_image("ch1a_07")')
    image_gallery.unlock_image("ch1a_03")
    image_gallery.unlock_image("ch1a_04")
    image_gallery.unlock_image("ch1a_05")
    image_gallery.unlock_image("ch1a_06")
    image_gallery.unlock_image("ch1a_07")

    image_gallery.button("slot04")
    image_gallery.condition('renpy.seen_image("ch1b_10")')
    image_gallery.unlock_image("ch1b_07")
    image_gallery.unlock_image("ch1b_08")
    image_gallery.unlock_image("ch1b_09")
    image_gallery.unlock_image("ch1b_10")

    image_gallery.button("slot05")
    image_gallery.condition('renpy.seen_image("ch1c_17")')
    image_gallery.image("ch1c_16_gallery")
    image_gallery.condition("True")
    image_gallery.unlock_image("ch1c_17")

    image_gallery.button("slot06")
    image_gallery.condition('renpy.seen_image("ch1e_12_movie")')
    image_gallery.unlock_image("ch1e_09a")
    image_gallery.unlock_image("ch1e_09b")
    image_gallery.unlock_image("ch1e_09c")
    image_gallery.unlock_image("ch1e_09d")
    image_gallery.unlock_image("ch1e_10")
    image_gallery.unlock_image("ch1e_10a")
    image_gallery.unlock_image("ch1e_11")
    image_gallery.unlock_image("ch1e_12_movie")

    image_gallery.button("slot07")
    image_gallery.condition('renpy.seen_image("ch1e_17_movie")')
    image_gallery.unlock_image("ch1e_15")
    image_gallery.unlock_image("ch1e_16")
    image_gallery.unlock_image("ch1e_17_movie")

    image_gallery.button("slot08")
    image_gallery.condition('renpy.seen_image("ch1e_22")')
    image_gallery.unlock_image("ch1e_19a")
    image_gallery.unlock_image("ch1e_19")
    image_gallery.unlock_image("ch1e_20a")
    image_gallery.unlock_image("ch1e_20")
    image_gallery.unlock_image("ch1e_21")
    image_gallery.unlock_image("ch1e_22")

    image_gallery.button("slot09")
    image_gallery.condition('renpy.seen_image("ch1e_34")')
    image_gallery.unlock_image("ch1e_25_00")
    image_gallery.unlock_image("ch1e_25_anim")
    image_gallery.unlock_image("ch1e_26")
    image_gallery.unlock_image("ch1e_27_movie")
    image_gallery.unlock_image("ch1e_28")
    image_gallery.unlock_image("ch1e_29")
    image_gallery.unlock_image("ch1e_33")
    image_gallery.unlock_image("ch1e_34")

    image_gallery.button("slot10")
    image_gallery.condition('renpy.seen_image("ch3a_06")')
    image_gallery.unlock_image("ch3a_06")

    image_gallery.button("slot11")
    image_gallery.condition('renpy.seen_image("ch3c_10")')
    image_gallery.unlock_image("ch3c_07")
    image_gallery.unlock_image("ch3c_08")
    image_gallery.unlock_image("ch3c_09")
    image_gallery.unlock_image("ch3c_10")
    image_gallery.unlock_image("ch3c_11")
    image_gallery.unlock_image("ch3c_12")
    image_gallery.unlock_image("ch3c_13")
    image_gallery.unlock_image("ch3c_14")
    image_gallery.unlock_image("ch3c_15")
    image_gallery.unlock_image("ch3c_16")
    image_gallery.unlock_image("ch3c_17")
    image_gallery.unlock_image("ch3c_18")
    image_gallery.unlock_image("ch3c_19")

    image_gallery.button("slot12")
    image_gallery.condition('renpy.seen_image("ch3c_29")')
    image_gallery.unlock_image("ch3c_27")
    image_gallery.unlock_image("ch3c_28")
    image_gallery.unlock_image("ch3c_29")

    image_gallery.button("slot13")
    image_gallery.condition('renpy.seen_image("ch3c_35a")')
    image_gallery.unlock_image("ch3c_32")
    image_gallery.unlock_image("ch3c_35")
    image_gallery.unlock_image("ch3c_35a")

    image_gallery.button("slot14")
    image_gallery.condition('renpy.seen_image("ch3c_37")')
    image_gallery.unlock_image("ch3c_37")

    image_gallery.button("slot15")
    image_gallery.condition('renpy.seen_image("ch3c_45")')
    image_gallery.unlock_image("ch3c_40")
    image_gallery.unlock_image("ch3c_41_movie")
    image_gallery.unlock_image("ch3c_42")
    image_gallery.unlock_image("ch3c_43")
    image_gallery.unlock_image("ch3c_44_00")
    image_gallery.unlock_image("ch3c_42a")
    image_gallery.unlock_image("ch3c_44_movie")
    image_gallery.unlock_image("ch3c_45")

    image_gallery.button("slot16")
    image_gallery.condition('renpy.seen_image("ch3c_51")')
    image_gallery.unlock_image("ch3c_46")
    image_gallery.unlock_image("ch3c_47")
    image_gallery.unlock_image("ch3c_48")
    image_gallery.unlock_image("ch3c_49")
    image_gallery.unlock_image("ch3c_50")
    image_gallery.unlock_image("ch3c_51")

    image_gallery.button("slot17")
    image_gallery.condition('renpy.seen_image("ch3d_18")')
    image_gallery.unlock_image("ch3d_17")
    image_gallery.unlock_image("ch3d_18")

    image_gallery.button("slot18")
    image_gallery.condition('renpy.seen_image("ch3d_32")')
    image_gallery.image("ch3_gallery_parker_fantasy")

    image_gallery_buttons_pages = [
        [
            ( "slot01", "Ch 1: Brad and Emily",     "ch0b/ch0b_09.jpg" ),
            ( "slot02", "Ch 1: Parker and Becky",   "ch0d/ch0d_24.jpg" ),
            ( "slot03", "Ch 2: Melanie\u2019s Bra", "ch1a/ch1a_03.jpg" ),
            ( "slot04", "Ch 2: Melissa Downblouse", "ch1b/ch1b_09.jpg" ),
            ( "slot05", "Ch 2: License Grab",       "ch1c/ch1c_16_0.jpg" ),
            ( "slot06", "Ch 2: The Search, Part 1", "ch1e/ch1e_09a.jpg" )
        ],
        [
            ( "slot07", "Ch 2: The Search, Part 2", "ch1e/ch1e_15.jpg" ),
            ( "slot08", "Ch 2: The Search, Part 3", "ch1e/ch1e_19a.jpg" ),
            ( "slot09", "Ch 2: The Search, Part 4", "animations/ch1e_25_00.jpg" ),
            ( "slot10", "Ch 3: A revealing time",   "ch3a/ch3a_06.jpg" ),
            ( "slot11", "Ch 3: Let\u2019s have the top", "ch3c/ch3c_07.jpg" ),
            ( "slot12", "Ch 3: And the rest",       "ch3c/ch3c_27.jpg" ),
        ],
        [
            ( "slot13", "Ch 3: Exposed",             "ch3c/ch3c_32.jpg" ),
            ( "slot14", "Ch 3: Full Search, Part 1", "ch3c/ch3c_37.jpg" ),
            ( "slot15", "Ch 3: Full Search, Part 2", "ch3c/ch3c_40.jpg" ),
            ( "slot16", "Ch 3: Dressing",           "ch3c/ch3c_46.jpg" ),
            ( "slot17", "Ch 3: Tits are tits",      "ch3d/ch3d_17.jpg" ),
            ( "slot18", "Ch 3: Parker\u2019s Fantasy", "ch3d/ch3_gallery_parker_fantasy.jpg" ),
        ]
    ]

screen gallery_buttons(data):
    for (name, title, thumbnail) in data:
        if name:
            vbox:
                $ the_button = image_gallery.make_button(name, gallery_thumbnail(thumbnail))
                add the_button
                if image_gallery.buttons[name].check_unlock():
                    text title
                else:
                    text ""
        else:
            text ""

screen gallery():
    default page = 1
    tag menu

    use game_menu(_("Gallery"), scroll="viewport"):

        style_prefix "gallery"

        vbox:
            xsize 940
            ysize 500
            label "Page [page]":
                xalign 0.5
                bottom_margin 10

            grid 3 2:
                style_prefix "gallery_slot"

                xalign 0.5
                yalign 0.5

                xspacing 30
                yspacing 20

                use gallery_buttons(image_gallery_buttons_pages[page-1])

            hbox:
                style_prefix "page"

                anchor (0.5, 0.0)
                pos(0.5, 1.0)

                spacing gui.page_spacing

                if page > 1:
                    textbutton _("<") action SetScreenVariable("page", page - 1)
                else:
                    textbutton  _("<") action NullAction()

                for i in range(1, len(image_gallery_buttons_pages) + 1):
                    textbutton "[i]" action SetScreenVariable("page", i)

                if page < len(image_gallery_buttons_pages):
                    textbutton _(">") action SetScreenVariable("page", page + 1)
                else:
                    textbutton  _(">") action NullAction()

style gallery_slot_text:
    size 18
    xalign 0.5
    yalign 0.0

style gallery_button is button:
    hover_background "#fff"

style gallery_button_text:
    size 24
    bold True
    color "#fff"
    hover_color "#000"
    underline True

style gallery_button_current is button
style gallery_button_current_text is gallery_button_text:
    underline False
    hover_color "#fff"
I can change the 'gallery_locked_button' for 'gallocked' and it will work since that is the name of my locked image file. This as is works fine but when i change the names to my own i get errors. Which lines should i change?
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
You shouldn't need the "init" section. If you have a file named "ch3_cg3.png", and if it's in your "game/images" directory or any subdirectory under that, you can just refer to it as "ch3_cg3". Ren'py automatically creates image references for all the images under the "game/images" directory by stripping off the extension. If Ren'py isn't finding them, possibly they're in the wrong directory, or else there's something wrong with the file format.

So, for your "ch3_cg3.png" image, assuming that it's in the correct directory and properly formatted, you should just be able to do:
Code:
    image_gallery.button("slot01")
    image_gallery.condition('renpy.seen_image("ch3_cg3")')
    image_gallery.unlock_image("ch3_cg3")
 

juls0

Newbie
Oct 19, 2019
19
5
done. Now i get "Could not find file 'ch0/ch0b_09.jpg'"
I'm assuming that is an image in the image_gallery_button_pages which i dont have

( "slot01", "Ch 1: Brad and Emily", "ch0b/ch0b_09.jpg" )

but if I change the name to my picture name it will show the same error message with the new name instead.

My images are under images/bg/characters
there i have folders for char1, char2, char3, and extra

I forgot to ask, do i need to make a separate thumbnail file or does the code resize the image to be the thumbnail?
 
Last edited:

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
Now i get "Could not find file 'ch0/ch0b_09.jpg'"
I'm assuming that is an image in the image_gallery_button_pages which i dont have

( "slot01", "Ch 1: Brad and Emily", "ch0b/ch0b_09.jpg" )
Of course. The code was taken from my own game and posted here, so obviously my images aren't your images.

but if I change the name to my picture name it will show the same error message with the new name instead.

My images are under images/bg/characters
there i have folders for char1, char2, char3, and extra
That is a path to an image file, relative to the "images" folder in your project, not an image name. So, you need to put in a path to the image in your project that you want to use. Without knowing details on exactly what image you're trying to use, I would guess you'd have to be doing something like

Code:
( "slot01", "The title you want to use on the slot",     "bg/characters/char1/some_image.jpg" )
I forgot to ask, do i need to make a separate thumbnail file or does the code resize the image to be the thumbnail?
The code handles generating the thumbnail. I would have thought this relatively obvious from:
Code:
    def gallery_thumbnail(thumbnail_name):
        return im.FactorScale(thumbnail_name, 0.2)
I don't mean to offend, but if someone's going to offer you pre-written code to do 95% of the work for you on a feature, you really should take some time to read the code and understand what it's doing. You can't expect to take something that was written for someone else's project and have it work in yours without being prepared to modify it to fit things like "where are the images I need in my project." In this particular case, all that is required is a basic understanding of how Ren'py handles images:
  • If an image is referenced as just as a string without any slashes (e.g. "ch3_cg3"), then this is an image name that references a file somewhere under the "images" directory. The file can have any extension that Ren'py understands as an image, and can be located in any directory under "images." So "ch3_cg3" would match "images/ch3_cg3.png", "images/ch3_cg3.jpg", or "images/some/path/i/set/up/ch3_cg3.webp"
  • If an image is referenced as a path (i.e. contains one or more slashes), then this is a file path, (usually) relative to the "images" directory, and MUST contain the correct extension for the file. so "abc/def.jpg" matches "images/abc/def.jpg" but not "images/abc/def.png" (wrong extension) or "images/some/other/path/def.jpg" (wrong location). "abc/def" won't match anything, because the extension is missing, and Ren'py won't recognize a file as an image without an extension.
This isn't something specific to this gallery code - this convention is used all throughout Ren'py. The gallery code is using Ren'py's underlying image management, so it follows all the same conventions that Ren'py does. You might need to read and understand items like
 

juls0

Newbie
Oct 19, 2019
19
5
Thank you. I'm still not fully understanding but now i see i have some general problems with my images and locations. I had that same problem with other gallery codes i have downloaded from other pages too, where the main issue was finding my images. I'll go back to square one.
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,382
Thank you. I'm still not fully understanding but now i see i have some general problems with my images and locations. I had that same problem with other gallery codes i have downloaded from other pages too, where the main issue was finding my images. I'll go back to square one.
With Ren'py, rule#1 is "put your images inside the 'images' folder." (In sub-directories under "images" is fine.) Granted, you can make it work if they're not, but it's WAY harder. Why not just follow their conventions, right? Similarly, if you put your sound files in the "audio" folder, they'll be "autolocated" just the way images are.