Index: wp-includes/rewrite-functions.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- wp-includes/rewrite-functions.php	(revision 33816)
+++ wp-includes/rewrite-functions.php	(revision )
@@ -317,6 +317,40 @@
 		if ( $id )
 			return $id;
 	}
+	/**
+	 * Check if we are working with an image file
+	 */
+	if ( preg_match( '#^https?://.*?(?:png|jpg|jpeg|gif)$#ui', $url ) ) {
+
+		/**
+		 * Okay, let's look to see if it's an attachment. Gotta get the upload dir's baseurl
+		 * to strip off the protocal, domain and root paths because attachments are not stored
+		 * as full urls but instead (typically) stored using yyy/mm/filename.ext" format.
+		 */
+		$upload_dir = wp_upload_dir();
+
+		/**
+		 * Get the path or the original size image by slicing the base image url off the front
+		 * and "-{$width}x{$height}" off the end, and adding the extension back.
+		 */
+		$regex = preg_quote( $upload_dir[ 'baseurl' ] ) . '/(.*?)\-\d+x\d+(\.(png|jpg|jpeg|gif))';
+		$filepath = preg_replace( "#^{$regex}$#i", "$1$2", $url );
+
+		/**
+		 * Look up the image in the metadata to see if it is attached
+		 */
+		global $wpdb;
+
+		if ( $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value='%s'", $filepath ) ) ) {
+			return $id;
+		}
+
+		/**
+		 * Hmmph. Didn't find anything. No clue what the ID is then.
+		 */
+		return 0;
+
+	}
 
 	// Check to see if we are using rewrite rules
 	$rewrite = $wp_rewrite->wp_rewrite_rules();
