This would be the code but I'm not sure what you mean with postID. There's no separate page with a post, only topics, so I assumed you mean the topic id which I used in my code.
{{if !isset( \IPS\Output::i()->metaTags['og:image'] )}}
{{$shareLogos = \IPS\Settings::i()->icons_sharer_logo ? json_decode( \IPS\Settings::i()->icons_sharer_logo, true ) : array();}}
{{foreach $shareLogos as $logo}}
<meta property="og:image" content="{file="$logo" extension="core_Icons" scheme="full"}">
{{endforeach}}
{{elseif \IPS\Request::i()->app == 'forums' AND \IPS\Request::i()->controller == 'topic'}}
{{$id = \IPS\Request::i()->id;}}
<meta property='og:image' content='https://www.domain.tld/img/{$id}.jpg'/>
{{else}}
<meta property='og:image' content='https://www.domain.tld/standardimage.jpg'/>
{{endif}}
That said, I'm also not sure if it will work at all, the condition looks weird and will probably always return the first part for topics.