How to make anki cards from image files in python?

Recently, I’ve been working on a python program which selectively occludes certain words from a PowerPoint which you would watch in lecture or something. The gist of it is that you load your lecture slides into the input folder as images (.png) and then the program will generate images with certain key terms blocked out on the slides (.png).

As of right now, I am trying to use the occluded output images and input images to substitute for ‘question’ and ‘answer’ on a normal card, respectively. I’ve tried using genanki already, and even though I got it to work, the media files don’t sync like they should.

I find this to be particularly challenging since the cards I am trying to make only consist of media files. I would really appreciate any recommendations on how to make a bunch of anki cards from all the image files I have.

Here is my resolution may helpful to you
1.make sure note-type for the image occusion exist on anki and copy this notetype name
2.use python code to create cards with the notetype ,use html img tag added to question/answer field to represent png;make sure anki module from pip installed (in my case anki==2.1.46)
following are my python code
this will create deck and export deck from windows temp to desktop,after this you should copy img files to anki collection media folder

import tempfile,os,shutil
from pathlib import Path
from anki.collection import Collection as aopen
from anki.exporting import AnkiPackageExporter
def export_deck(col:Collection):
    e = AnkiPackageExporter(col)
    # write to Temp dir
    fd, newname = tempfile.mkstemp(prefix="ankitest", suffix=".apkg")
    newname = str(newname)

    # cp file to desktop
def add_cards_export_deck():
    # anki collection path
    col = aopen(nam)
    # create a new deck
    newId ="new_deck")
    # first must create/choose a  note tyoe on anki,
    # then model name can be accessed
    # note type pasted here
    m = col.models.by_name('Basic-0cc42')
    # choose deck for model by did
    m["did"] =newId, updateReqs=False)
    # print deck id and name
    # print(col.decks.all_names_and_ids())
    note = col.new_note(m)
    # card field
    note["question"] = '<img src="image27372.jpeg" >'
    note["answer"] = '<img src="image27372.jpeg" >'

the code mainly is from anki module anki/pylib/tests

You might want to take a look at this addon, which does precisely what you are looking for (ie. it allows to load an image, to select portions of text to be hidden, and then generates the appropriate cards - which is what you are looking to automate). I haven’t read fully the source code, but I have the impression that it generates a note for each question you ask (and not a card for each question), each note has only one card, and the media (ie. the image and the mask) are in fields. Then, there is some javascript inside the template that does the proper rendering.

Warning, your code is OS and profile specific, meaning that it will not work if my OS is not windows or if my profile name is not swjz.