Get Image Attachment ID from Image URL in WP

WordPress added the function attachment_url_to_postid($url) in version WP version 4.0.0.

This snippet is great, but if you need to find the ID from the URL that includes the cropped attributes, then you may need to add this snippet to your WordPress theme’s functions.php file.