This is a lot simpler than you think it is and to be honest you probably have the tool already. The tool you need is just unzip as all .docx documents are simply just zip files.
If you're on a Debian based system apt (or apt-get) install unzip
if you're on a system that uses yum: yum install unzip
once you have the command unzip run this command first and you can see the exact file path for whatever you're specifically trying to extract.
unzip -l filename
or you can get a little more detailed information that will still show you the file path with
Once you do either of those commands you will see that all the images in any .docx file are saved under word/media/
So to extract only the pictures from the .docx file would look as follows
unzip filename "word/media/*"
I know on my system you don't need to run quotes on $2("word/media/*")
but make sure you include the * wildcard after word/media/ to get all the pictures in the file.
If you want a specific file you can also specify that specific file. (You would no longer use the * wildcard.)
If you can't find the zipinfo command unzip -Z is the same thing.