For MP3, try eyeD3, found in this SO answer.
--add-image=IMG_PATH:TYPE[:DESCRIPTION]
Add an image to the tag. The description and type
optional, but when used, both ':' delimiters must be
present. The type MUST be an string that corresponds
to one given with --list-image-types. If the IMG_PATH
value is empty the APIC frame with TYPE is removed.
For Ogg, there's vorbiscomment. It doesn't support loading image files out of the box, but a cover art tag in Vorbis is just an image file encoded in base64, stored in the COVERART tag and its mimetype in COVERARTMIME - something like
coverart=$(base64 $jpegfile)
vorbiscomment -a -t 'COVERART=$coverart' -t 'COVERARTMIME=image/jpeg' $infile $outfile