diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php
index 3aae94d1a4ff271619d172ed0de6cfc112133f6f..9fdadbe38c714a248fe60f1f933814cafc6b134b 100644
--- a/apps/gallery/lib/scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -89,8 +89,11 @@ class OC_Gallery_Scanner {
     $file_count = min(count($files), 10);
     $thumbnail = imagecreatetruecolor($file_count*200, 200);
     for ($i = 0; $i < $file_count; $i++) {
-		$imagePath = OC_Filesystem::getLocalFile($files[$i]);
-      CroppedThumbnail($imagePath, 200, 200, $thumbnail, $i*200);
+      $image = OC_Gallery_Photo::getThumbnail($files[$i]);
+      if ($image && $image->valid()) {
+	      imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200);
+      }
+      unset($image); // unset $image here to control the lifetime of image::$resource
     }
     imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png');
   }