From 73c6db5c8e6d876adf7b6c1c91049c66be26ba87 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Mar 2012 23:53:48 +0200 Subject: crop and resize in a single step when creating thumbnail also so more explicit memory cleanup --- apps/gallery/lib/photo.php | 11 ++++++----- apps/gallery/lib/scanner.php | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'apps/gallery') diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index 2263608dcc2..3bb6f9129fa 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -72,6 +72,9 @@ class OC_Gallery_Photo { $save_dir .= dirname($image_name). '/'; $image_path = $image_name; $thumb_file = $save_dir . basename($image_name); + if (!is_dir($save_dir)) { + mkdir($save_dir, 0777, true); + } if (file_exists($thumb_file)) { $image = new OC_Image($thumb_file); } else { @@ -81,17 +84,15 @@ class OC_Gallery_Photo { } $image = new OC_Image($image_path); if ($image->valid()) { - $image->centerCrop(); - $image->resize(200); + $image->centerCrop(200); $image->fixOrientation(); - if (!is_dir($save_dir)) { - mkdir($save_dir, 0777, true); - } $image->save($thumb_file); } } if ($image->valid()) { return $image; + }else{ + $image->destroy(); } return null; } diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index 34b9bb8da3d..6d2d44d428f 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -79,6 +79,7 @@ class OC_Gallery_Scanner { if ($image && $image->valid()) { imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200); } + $image->destroy(); } imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png'); imagedestroy($thumbnail); -- cgit v1.2.3