I had a similar problem, but I’m using the WP Read Only plugin (I’m running WordPress on Heroku). This plugin makes sure all images are uploaded to S3. The thumbnails were null also.
I rewritten the above function and deleted the checks whether the file exists. It works now, but obviously does not check for the file’s existence:
function query_images() {
$sizes = array('thumbnail', 'medium', 'large', 'full');
if (function_exists('get_intermediate_image_sizes')) {
$sizes = array_merge(array('full'), get_intermediate_image_sizes());
}
$this->images = array();
$home = get_bloginfo('url');
$upload_dir = wp_upload_dir();
$basedir = $upload_dir['basedir'];
$file = get_post_meta($this->id, '_wp_attached_file', true);
foreach ($sizes as $size) {
list($url, $width, $height) = wp_get_attachment_image_src($this->id, $size);
$filename = $basedir . '/' . str_replace(basename($file), basename(parse_url($url, PHP_URL_PATH)), $file);
list($measured_width, $measured_height) = getimagesize($filename);
$this->images[$size] = (object) array(
'url' => $url,
'width' => $width,
'height' => $height
);
}
}