def SaveScenesToFile()

in renderer/glViewer.py [0:0]


def SaveScenesToFile():
    global g_saveImageName_last
    #global g_Width, g_Height, g_bSaveToFile, g_fameIdx, g_hagglingseq_name
    # global g_bSaveToFile
    # global g_saveFrameIdx

    glReadBuffer(GL_FRONT)
    img = glReadPixels(0, 0, g_Width, g_Height, GL_RGBA, GL_UNSIGNED_BYTE, outputType=None)
    img = Image.frombytes("RGBA", (g_Width, g_Height), img)
    img = ImageOps.flip(img)

    if False:
        pix = np.array(img)
        from renderer import viewer2D
        viewer2D.ImShow(pix)


    #Crop and keep the original size
    # if g_textureImgOriginal is not None and g_viewMode=='camView':
    #     width, height = img.size
    #     img = img.crop( (0,0,g_textureImgOriginal.shape[1], g_textureImgOriginal.shape[0]))     #top, left, bottom, right where origin seems top left

    if g_renderOutputSize is not None and g_viewMode=='camView':
        width, height = g_renderOutputSize
        img = img.crop( (0,0,width, height))     #top, left, bottom, right where origin seems top left


    #img.save('/ssd/render_general/frame_{}.png'.format(g_frameIdx), 'PNG')
    if g_saveFolderName is not None:
        folderPath = g_saveFolderName
    else:# g_haggling_render == False:
        # folderPath = '/home/hjoo//temp/render_general/'
        folderPath = '/home/hjoo//temp/render_general/'
    # else:
    #     if g_meshes == None and g_hagglingFileList == None: #Initial loading
    #         LoadHagglingData_Caller() #Load New Scene
    #     folderPath = '/hjoo/home/temp/render_mesh/' + g_hagglingseq_name
    #     if os.path.exists(folderPath) == False:
    #         os.mkdir(folderPath)

    if os.path.exists(folderPath) == False:
        os.mkdir(folderPath)
    # img.save('{0}/scene_{1:08d}.png'.format(folderPath,g_saveFrameIdx), 'PNG')
    img = img.convert("RGB")

    if g_saveImageName is not None:
        g_saveImageName_last = '{0}/{1}.jpg'.format(folderPath,g_saveImageName)
    else:
        g_saveImageName_last = '{0}/scene_{1:08d}.jpg'.format(folderPath,g_saveFrameIdx)
    
    img.save(g_saveImageName_last, "JPEG")

    print(f"Render image to:{g_saveImageName_last}")

    # print(img.size)
    # g_saveFrameIdx +=1
    #Done saving
    global g_bSaveToFile_done
    g_bSaveToFile_done = True