wp_get_attachment_image_src() with advanced custom fields returning empty

What’s in get_sub_field(‘image’)? wp_get_attachment_image_src() parameter 1 should be the attachment id, not the attachment src, if that’s what you have.

I use the following function to get an attachment ID from an image url as as far as I know WP doesn’t have a method for this at present.

function get_attachment_id_from_src ($src) {
    global $wpdb;

    $reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i";

    $src1 = preg_replace($reg,'',$src);

    if($src1 != $src){
    $ext = pathinfo($src, PATHINFO_EXTENSION);
    $src = $src1 . '.' .$ext;
}

$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);

return $id;

}