I have some images named like this in a folder:
Image_00036.jpg
Image_00037.jpg
Image_00038.jpg
Image_00039.jpg
I want to create some cards. Each card will have the even numbered images for its front and the odd numbered images for its back. How can I do that automatically without having to manually drag and drop each image ?
- 833
2 Answers
Step 1. Prepare metadata
I suppose that you already know:
- How to create new deck (not neccessary, but makes sense)
- How to define new note type
- How to define cards for note type
- Import from delimited text file
If not - check documentation, it's not complex.
You need to create a note type with at least 3 fields: Id, FrontImage, BackImage
Step 2.Generate delimited text file
I suppose that your image files are numbered from 0 to N with preceding zeroes. E.g if N=100,then image names are: image00000.jpg - image00100.jpg.
The goal: create delimited text file with content like:
Card_00000;<img src="Image_00000.jpg"/>;<img src="Image_00001.jpg"/>
Card_00001;<img src="Image_00002.jpg"/>;<img src="Image_00003.jpg"/>
Card_00002;<img src="Image_00004.jpg"/>;<img src="Image_00005.jpg"/>
Card_00003;<img src="Image_00006.jpg"/>;<img src="Image_00007.jpg"/>
Card_00004;<img src="Image_00008.jpg"/>;<img src="Image_00009.jpg"/>
Card_00005;<img src="Image_00010.jpg"/>;<img src="Image_00011.jpg"/>
Card_00006;<img src="Image_00012.jpg"/>;<img src="Image_00013.jpg"/>
Card_00007;<img src="Image_00014.jpg"/>;<img src="Image_00015.jpg"/>
Card_00008;<img src="Image_00016.jpg"/>;<img src="Image_00017.jpg"/>
Card_00009;<img src="Image_00018.jpg"/>;<img src="Image_00019.jpg"/>
Card_00010;<img src="Image_00020.jpg"/>;<img src="Image_00021.jpg"/>
Card_00011;<img src="Image_00022.jpg"/>;<img src="Image_00023.jpg"/>
Recipe 1. Use script language
In python generation can be:
print("\n".join(['Card_%05d;<img src="Image_%05d.jpg"/>;<img src="Image_%05d.jpg"/>' % (image_number,image_number*2, image_number*2 +1 )
for image_number in range(0, int(100/2))]))
Recipe 2. Use spreadsheet
If you're more comfortable with office tools you can use spreadsheet.
You need to create: autoincrementing field and 2 calculated fields.
Example: https://docs.google.com/spreadsheets/d/1W1DQ2ZSm4XuYNeKlkybbTeXh7RGqkk8H-7CgCaBVeI4/pubhtml
Formula for front:
= Concatenate("<src img=""Image", Text(A2*2-1,"00000"),".jpg"" />")
Step 3. Save in file, import, copy images to media folder, enjoy
Exactly so.
Good luck!
- 131
Please note that the formula for using the "Recipe 2" spreadsheet method should be
= Concatenate("<img src=""Image", Text(A2*2-1,"00000"),".jpg"" />")
In the answer by Alex Yu, the formula lists "src img" which will not be recognized by Anki. Your output must be in "img src" format.
If your files start a 1 without proceeding zeros, you can code this as:
= Concatenate("<img src=""Image", Text(A2*2-1,"0"),".jpg"" />")
If your files are from PowerPoint and are named "Slide1", then you can change the formula to be:
= Concatenate("<img src=""Slide", Text(A2*2-1,"0"),".jpg"" />")
Additionally, if your image files are .jepg, then change the ".jpg" in the formula to be ".jepg" and it will work correctly without needing to convert your files.