From 0c19e44a61229fe1376c8436b8a73e974b424539 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Mar 2012 22:28:40 +0200 Subject: some more memory cleanup in OC_Image --- lib/image.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/image.php b/lib/image.php index 60a714880d0..62f35b4fc99 100644 --- a/lib/image.php +++ b/lib/image.php @@ -526,6 +526,7 @@ class OC_Image { imagedestroy($process); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } @@ -558,7 +559,14 @@ class OC_Image { imagedestroy($process); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } + + public function __destruct(){ + if(is_resource($this->resource)){ + imagedestroy($this->resource); + } + } } -- cgit v1.2.3 From 0ba93323585cd277d845eb7d7600cd4cac4f84da Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 26 Mar 2012 22:33:37 +0200 Subject: some more memory cleanup in OC_Image --- lib/image.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/image.php b/lib/image.php index 62f35b4fc99..4717f81af7d 100644 --- a/lib/image.php +++ b/lib/image.php @@ -317,10 +317,7 @@ class OC_Image { */ public function loadFromFileHandle($handle) { OC_Log::write('core',__METHOD__.'(): Trying', OC_Log::DEBUG); - $contents = ''; - while (!feof($handle)) { - $contents .= fread($handle, 8192); - } + $contents = stream_get_contents($handle); if($this->loadFromData($contents)) { return $this->resource; } @@ -486,6 +483,7 @@ class OC_Image { imagedestroy($process); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } -- cgit v1.2.3 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 + lib/image.php | 26 ++++++++++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) (limited to 'lib') 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); diff --git a/lib/image.php b/lib/image.php index 4717f81af7d..b3c7d52ec2c 100644 --- a/lib/image.php +++ b/lib/image.php @@ -216,7 +216,7 @@ class OC_Image { OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG); return false; } - $exif = @exif_read_data($this->filepath, 'IFD0'); + $exif = @exif_read_data($this->filepath, 'IFD0'); if(!$exif) { return false; } @@ -267,6 +267,7 @@ class OC_Image { if($res) { if(imagealphablending($res, true)) { if(imagesavealpha($res, true)) { + imagedestroy($this->resource); $this->resource = $res; return true; } else { @@ -490,9 +491,10 @@ class OC_Image { /** * @brief Crops the image to the middle square. If the image is already square it just returns. + * @param int maximum size for the result (optional) * @returns bool for success or failure */ - public function centerCrop() { + public function centerCrop($size=0) { if(!$this->valid()) { OC_Log::write('core','OC_Image->centerCrop, No image loaded', OC_Log::ERROR); return false; @@ -512,13 +514,20 @@ class OC_Image { $y = ($height_orig/2) - ($height/2); $x = 0; } - $process = imagecreatetruecolor($width, $height); + if($size>0){ + $targetWidth=$size; + $targetHeight=$size; + }else{ + $targetWidth=$width; + $targetHeight=$height; + } + $process = imagecreatetruecolor($targetWidth, $targetHeight); if ($process == false) { OC_Log::write('core','OC_Image->centerCrop. Error creating true color image',OC_Log::ERROR); imagedestroy($process); return false; } - imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $width, $height, $width, $height); + imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); if ($process == false) { OC_Log::write('core','OC_Image->centerCrop. Error resampling process image '.$width.'x'.$height,OC_Log::ERROR); imagedestroy($process); @@ -562,9 +571,14 @@ class OC_Image { return true; } - public function __destruct(){ - if(is_resource($this->resource)){ + public function destroy(){ + if($this->valid()){ imagedestroy($this->resource); } + $this->resource=null; + } + + public function __destruct(){ + $this->destroy(); } } -- cgit v1.2.3 From 266699ddf90a074aa4c4f5b50a63f5f430842bde Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 27 Mar 2012 00:42:15 +0200 Subject: fix square images not getting proper thumbnails --- lib/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/image.php b/lib/image.php index b3c7d52ec2c..4c53dc32f58 100644 --- a/lib/image.php +++ b/lib/image.php @@ -501,7 +501,7 @@ class OC_Image { } $width_orig=imageSX($this->resource); $height_orig=imageSY($this->resource); - if($width_orig === $height_orig) { + if($width_orig === $height_orig and $size==0) { return true; } $ratio_orig = $width_orig/$height_orig; -- cgit v1.2.3 From bcef775d6bc93144316d4eea74f90c5be03576b0 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 27 Mar 2012 01:18:38 +0200 Subject: Overwrite Download-ZIP if it already exists. We do not want to show alien content. --- lib/files.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/files.php b/lib/files.php index 57ebb9005ad..f1cf7573bae 100644 --- a/lib/files.php +++ b/lib/files.php @@ -64,7 +64,7 @@ class OC_Files { set_time_limit(0); $zip = new ZipArchive(); $filename = get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } foreach($files as $file){ @@ -85,7 +85,7 @@ class OC_Files { set_time_limit(0); $zip = new ZipArchive(); $filename = get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } $file=$dir.'/'.$files; -- cgit v1.2.3 From 24bc639222b3f4344bed388ca7fd834f8e70dff8 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 27 Mar 2012 01:19:34 +0200 Subject: Do not use always the same name for download-zip to avoid collisions. --- lib/files.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/files.php b/lib/files.php index f1cf7573bae..e7bfbbc19bb 100644 --- a/lib/files.php +++ b/lib/files.php @@ -63,7 +63,7 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir()."/ownCloud.zip"; + $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } @@ -84,7 +84,7 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir()."/ownCloud.zip"; + $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } -- cgit v1.2.3 From c92fc9bf651e79aa44803eeeed1d16499a5f08e6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 27 Mar 2012 02:24:52 +0200 Subject: return path of tmp file like filestorage/common does. Fixes broken folder-/multifile-download. --- lib/filesystemview.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 89e0385fe9c..39e47975b28 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -23,11 +23,11 @@ class OC_FilesystemView { private $fakeRoot=''; - + public function __construct($root){ $this->fakeRoot=$root; } - + public function getAbsolutePath($path){ if(!$path){ $path='/'; @@ -141,7 +141,7 @@ class OC_FilesystemView { while (!feof($handle)) { echo fread($handle, $chunkSize); @ob_flush(); - flush(); + flush(); } return $this->filesize($path); } @@ -282,7 +282,8 @@ class OC_FilesystemView { if($source){ $extention=substr($path,strrpos($path,'.')); $tmpFile=OC_Helper::tmpFile($extention); - return file_put_contents($tmpFile,$source); + file_put_contents($tmpFile,$source); + return $tmpFile; } } } -- cgit v1.2.3