[SOLVED]Applying image manipulators (ex:crop) to thumbnails?

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
Lora
Regular
Posts: 25
Joined: Sat Jan 04, 2014 4:55 am
Projects: High Fog
Location: Texas
Contact:

[SOLVED]Applying image manipulators (ex:crop) to thumbnails?

#1 Post by Lora »

Just wondering if it's possible to add image manipulators (crop, alpha mask, color matrices, etc) to the thumbnail of a save file before it's displayed via add FileScreenshot() to the File Picker. Not necessary but would be a cool touch!
Last edited by Lora on Sat May 10, 2014 4:47 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#2 Post by PyTom »

Hm... doing so will probably work, but it will be slow. If you can do what you want with a Transform, it will work better (and I know it will work).
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#3 Post by Asceai »

crop is best done with the crop transform property. alphamask is best done with alphablend. colour matrices.. you're on your own.

User avatar
Lora
Regular
Posts: 25
Joined: Sat Jan 04, 2014 4:55 am
Projects: High Fog
Location: Texas
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#4 Post by Lora »

Ah, I didn't realize there was a crop transform property! That's working out nicely! I've tried out the AlphaBlend, but it doesn't really work the way an AlphaMask would, does it, since you have to provide the image to blend into? I have a complicated background (for the entire file picker screen) that I have "fading into" the thumbnail image. (non-animated)

Anyway, conclusion reached, image manipulators DO work with the thumbnails, which is cool! I haven't tried color matrices, but the AlphaMask was most of what I was going for. I haven't noticed any slowness yet, though I have a fairly good computer. I really like the effect I got, but I also don't wanna tax the system too much. Hmm. Well, will cross that bridge when I get to it I guess!

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#5 Post by Asceai »

Lora wrote:Ah, I didn't realize there was a crop transform property! That's working out nicely! I've tried out the AlphaBlend, but it doesn't really work the way an AlphaMask would, does it, since you have to provide the image to blend into? I have a complicated background (for the entire file picker screen) that I have "fading into" the thumbnail image. (non-animated)
Just provide Solid("#0000") or some other transparent displayable to fade to.

User avatar
Lora
Regular
Posts: 25
Joined: Sat Jan 04, 2014 4:55 am
Projects: High Fog
Location: Texas
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#6 Post by Lora »

D'oh, I should have thought of that. Might implement that later.

Sooo my fading images loadscreen works well, until I try to access the second page (where no saves and hence thumbnails exist)


Then I get this error:
I'm sorry, but an uncaught exception occurred.

While running game code:
File "renpy/common/_layout/screen_main_menu.rpym", line 29, in script
File "game/screens.rpy", line 303, in python
File "game/screens.rpy", line 284, in python
File "game/screens.rpy", line 233, in python
Exception: Expected an image, but got a general displayable.

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\execution.py", line 294, in run
node.execute()
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\ast.py", line 732, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\python.py", line 1382, in py_exec_bytecode
exec bytecode in globals, locals
File "renpy/common/_layout/screen_main_menu.rpym", line 29, in <module>
$ ui.interact()
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\ui.py", line 237, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\core.py", line 2059, in interact
scene_lists.replace_transient()
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\core.py", line 577, in replace_transient
self.remove(layer, tag)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\core.py", line 851, in remove
self.hide_or_replace(layer, remove_index, "hide")
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\core.py", line 775, in hide_or_replace
d = oldsle.displayable._hide(now - st, now - at, prefix)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\screen.py", line 189, in _hide
hid.update()
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\screen.py", line 270, in update
self.screen.function(**self.scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\screenlang.py", line 1236, in __call__
renpy.python.py_exec_bytecode(self.code.bytecode, locals=scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\python.py", line 1382, in py_exec_bytecode
exec bytecode in globals, locals
File "game/screens.rpy", line 303, in <module>
use file_picker
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\screen.py", line 599, in use_screen
screen.function(**scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\screenlang.py", line 1236, in __call__
renpy.python.py_exec_bytecode(self.code.bytecode, locals=scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\python.py", line 1382, in py_exec_bytecode
exec bytecode in globals, locals
File "game/screens.rpy", line 284, in <module>
use load_save_slot(number=1)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\screen.py", line 599, in use_screen
screen.function(**scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\screenlang.py", line 1236, in __call__
renpy.python.py_exec_bytecode(self.code.bytecode, locals=scope)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\python.py", line 1382, in py_exec_bytecode
exec bytecode in globals, locals
File "game/screens.rpy", line 233, in <module>
add im.AlphaMask(FileScreenshot(number), "gui/testmask.jpg") xpos 12 ypos 12
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\im.py", line 1482, in __init__
self.base = image(base)
File "C:\Users\Lora\Downloads\renpy-6.17.4-sdk\renpy\display\im.py", line 1551, in image
raise Exception("Expected an image, but got a general displayable.")
Exception: Expected an image, but got a general displayable.

Windows-post2008Server-6.2.9200
Ren'Py 6.18.0.409
High Fog 0.0
I know it's something to do with how FileScreenshot(number) doesn't exist for those nonexistent saves. Here's the original code:

Code: Select all

    
$ file_text = "{font=fonts/pfarma.ttf}{color=#fff}{size=16}% s\n  {/size}%s{/color}" % (FileTime(number, empty="Empty Slot."), FileSaveName(number))
add im.AlphaMask(FileScreenshot(number), "gui/testmask.jpg") xpos 12 ypos 12
text file_text  xpos 180 ypos -10 size 20

then I tried to fix it I tried something like:

Code: Select all

    
if renpy.exists(FileScreenshot(number)):
        add im.AlphaMask(FileScreenshot(number), "gui/testmask.jpg") xpos 12 ypos 12
However, this stops all screenshots from being displayed, even the ones that exist. I'm guessing renpy.exists wasn't meant to be used with this sort of functionality...?

Any ideas?

(Thanks Asceai and PyTom for the help so far!)

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#7 Post by Asceai »

FileScreenshot on an empty saveslot returns a Null(), which is a displayable, not an image manipulator, _unless_ you specify an 'empty' param, then it returns that param instead.

So you need to supply an empty param. Something like:
default empty_screenshot = Image("empty_screenshot.png")
add im.AlphaMask(FileScreenshot(number, empty=empty_screenshot), "gui/testmask.jpg") xpos 12 ypos 12

User avatar
Lora
Regular
Posts: 25
Joined: Sat Jan 04, 2014 4:55 am
Projects: High Fog
Location: Texas
Contact:

Re: Applying image manipulators (ex: crop) to thumbnails?

#8 Post by Lora »

Ohh, I get it! Thanks so much! It works perfectly now! :D

Post Reply

Who is online

Users browsing this forum: Ocelot