Hello! In each gallery script, at the top where you define the buttons/add the images you'll notice a line that looks like
g.condition("persistent.pg1_1")This basically ties the 'availability' to a variable. If that variable is true, the image is unlocked, if false, locked. Now, variables usually reset when a new playthrough is started, that's why 'persistent.' is added, so it becomes a persistent variable and once the image is unlocked, it stays unlocked no matter.
So, to unlock an image in the script, the first on the first page in this case, you'd write:
$ persistent.pg1_1 = True
I recommend reading through the Gallery and Persistent Data part of the documentation as well as maybe Visual Novel Design's general Ren'py quickstart video (variables are in the chapter 'Some Math is Involved')