Retrive images from the_content()

There are essentially three criteria here:

  • do images belong to the site (are WP attachments)
  • are images attached to this post
  • are images used in this post

This has side effects, like:

  • images used in post are not necessarily attachments
  • post’s attachments aren’t necessarily used in that post

So the only reliable way to produce complete set of images, actually used in specific post’s content is indeed to parse the content (after shortcodes like galleries and embeds) for them.

After that you can [try] reverse engineer URLs into WP’s attachments, see Turn a URL into an Attachment / Post ID for example.