Find and collect USED/SELECTED images/files on a page

Do you want to do this only on a per page basis? in all page content or just the blocks field? Or check all images over the whole site?

For a single page and the images belonging to this page:

<?php
// Get all uuids of the page's images
$uuids = $page->images()->pluck('uuid', ',');
// Get the block/layouts field value and remove the slashes
$block = stripslashes($page->layout()->value());
// Create a pattern from the uuids by exploding the array
preg_match_all(
    '!\(' . implode('|', $uuids) . '\)!',
    $block,
    $matches
);
// $matches returns an array of uuids present in the given string
dump($matches);