--- node_gallery.pages.inc	Sun Nov 08 18:14:28 2009
+++ node_gallery.pages.inc	Wed Nov 18 12:01:08 2009
@@ -287,12 +287,15 @@
   //if this is new upload, then fid is file id;
   //if this is edit images, then fid is node id;
   //but fid is just an identifier here, so needn't care it.
+  // only do this if there is an image
+  if (!empty($gallery->images) && is_array($gallery->images)) {
   foreach ($gallery->images as $fid => $f) {
     $options[$fid] = '';
     if ($f->is_cover) {
       $cover_fid = $fid;
     }
   }
+  }
   $form['is_cover'] = array(
     '#type' => 'radios',
     '#default_value' => $cover_fid,
@@ -372,11 +375,14 @@
   //if this is new upload, then fid is file id;
   //if this is edit images, then fid is node id;
   //but fid is just an identifier here, so needn't care it.
+  // only do this if there is an image
+  if (!empty($gallery->images) && is_array($gallery->images)) {
   foreach ($gallery->images as $fid => $f) {
     $options[$fid] = '';
     if ($f->is_cover) {
       $cover_fid = $fid;
     }
   }
+  }
   $form['is_cover'] = array(
     '#type' => 'radios',
