So long story short I did some digging and found that the game saves the generated portrait image as encoded text within the savegame's global.lsf file, using a similar principle as resetting the companion portraits you can then override the used image to whatever you want.

Tools you'll need:


1. Go to the game install directory, inside the Data folder you'll find a file called Icons.pak, unpack it somewhere using the PAK Extractor (make sure to use the EXTRACT PACKAGE button and not the CREATE PACKAGE button which will override your game files and force you to verify integrity to get the file back) like your desktop and navigate to it (image).

2. In the unpacked folder navigate inside to Public\Shared\Assets\Textures\Icons, inside there you'll find a bunch of .dds files, the one you're interested in is, this file contains the default portrait images that get used if the player doesn't have one generated, they are start from the top left and moving right for each race and gender.

3. From here you can start editing the file to add your own custom portrait image, make sure to put it directly over the existing one for the race and gender of your character, each image is 80px*100px, when you are done make sure to save the file using these settings.

Note: If you are not sure which image to override in the file, skip to step 5, launch the game after you're done, and then you should see which image the game is using so you can override it).

4. After saving the new DDS file with your new custom portrait image, place it in the game directory with the exact same path inside the Data folder, so it should be somewhere like: C:\GoG Games\Divinity - Original Sin 2\Data\Public\Shared\Assets\Textures\Icons.

5. Now everything in place but the game will still prioritize the generated portrait image, next up we need to go to our save file and remove the generated image from there, so go to your save folder, in my case on Windows 10 it was located in:
C:\Users\<Your User Name>\OneDrive\Documents\Larian Studios\Divinity Original Sin 2\PlayerProfiles\<Your Profile Name>\Savegames\Story\<Save Title>\

What you need to do here is extract the .lsv file inside the save folder ( image).

6. Convert the globals.lsf file in the extracted save folder to globals.lsx, now you can open the globals.lsx file using an XML text editor (as stated above, I used Notepad++). Please be advised that this is a huge file and might lag your computer for a second or two.

After it opens up, search for "PlayerCustomData" until you find a node that contains an attribute with your character name:
<attribute id="Name" value="Sylvia" type="30" />

Inside the same node there will be an attribute called "CustomIconImg", this will normally have a long string of characters as value (which I assume in base64 encoded image?), what you need to do here is delete the value, so it should look like:
<attribute id="CustomIconImg" value="" type="25" />

Now repeat the same thing for the other entry for your character that you'll find (I'm not sure this is necessary, but I found that one entry is a bogus one that isn't being used or is only used for part of the game), save and close the file.

7. Go back to the PAK Extractor, convert globals.lsx back to globals.lsf(image), and remove the .lsx file from the directory (removal isn't required but the file is no longer necessary and will otherwise get repacked into the save file).

8. Now all you need is to create the package for the save file, you should already be pointing towards the correct directories if you haven't closed the PAK Extractor, if so all you need to do is press "Create Package" and it will be created and placed on top of your save file.

9. You're done! Load up the save file you just edited and you should have your edited image used as portrait icon instead of the generated one! (image)

Note: If you do something that causes your portrait to be generated again you'll need to go through steps 5-9 again, but I think that only happens when you use the respec mirror?

If you're playing using one of the origin characters I believe the same steps apply, but you will have to override one of the portraits on the lower right side of the DDS file instead of the race/gender ones at the top left.

For NPC companions (and other NPCs in general) you can also edit their portrait images by extracting Patch5.pak and editing the following DDS file inside it:
No portrait reset needed for this, just place it following the same directory path inside the Data folder in the game directory and it will work.

Someone could probably figure out an easier way by just encoding a new portrait image directly in the savegame XML file since I wasn't able to figure out what encoding they used for it (it definitely wasn't base64 ASCII or UTF8, so either it's a different character set or password protected or it's not base64 to begin with).

Also from the dev side an easier way would be for the generated image to be saved somewhere as PNG and then loaded later so we can edit it without needing to mess with the game files, but I suppose it's too late for that sort of change now smirk