Post-upgrade problems: Image URL in DB, but not showing

I don’t have time to produce working code for this. I will edit the answer if I get the chance.

In the meantime, you probably want a filter on upload_dir to alter that path.

Your code would look something like this then:

function alter_upload_wpse_107016($upload) {
  remove_filter('upload_dir','alter_upload_wpse_107016');
  // alter $upload array
  return $upload;
}
if (1 === preg_match('|regex-to-check-guid|',$terms[$i]->guid) {
  add_filter('upload_dir','alter_upload_wpse_107016');
}
$gallery_image_thumb = wp_get_attachment_image_src($terms[$i]->ID, 'thumbnail');

That is completely untested and written entirely from memory. No promises but maybe it will get you started.

By the way, the guid is not an URL, however much it may look like one, and should not be used as such (even though it was used as such by WordPress prior to something like 2.7).