diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-03-27 20:54:16 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-03-27 20:54:16 +0200 |
commit | 536a3ecb428b9450a188de4a0fcca2f9be6318f3 (patch) | |
tree | 26e866877d07e528ca12c1317698f5debe0c30c4 /lib | |
parent | ac0c5ba6daf5ffe84088571ea307f5223bd1049a (diff) | |
parent | cb2dd97509ffd039fbd321aea4a8d631e3effcc7 (diff) | |
download | nextcloud-server-536a3ecb428b9450a188de4a0fcca2f9be6318f3.tar.gz nextcloud-server-536a3ecb428b9450a188de4a0fcca2f9be6318f3.zip |
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'lib')
-rw-r--r-- | lib/files.php | 8 | ||||
-rw-r--r-- | lib/filesystemview.php | 9 | ||||
-rw-r--r-- | lib/image.php | 38 |
3 files changed, 38 insertions, 17 deletions
diff --git a/lib/files.php b/lib/files.php index 57ebb9005ad..e7bfbbc19bb 100644 --- a/lib/files.php +++ b/lib/files.php @@ -63,8 +63,8 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { + $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } foreach($files as $file){ @@ -84,8 +84,8 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir()."/ownCloud.zip"; - if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { + $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; + if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } $file=$dir.'/'.$files; 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; } } } diff --git a/lib/image.php b/lib/image.php index 60a714880d0..4c53dc32f58 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 { @@ -317,10 +318,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,22 +484,24 @@ class OC_Image { imagedestroy($process); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } /** * @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; } $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; @@ -514,18 +514,26 @@ 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); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } @@ -558,7 +566,19 @@ class OC_Image { imagedestroy($process); return false; } + imagedestroy($this->resource); $this->resource = $process; return true; } + + public function destroy(){ + if($this->valid()){ + imagedestroy($this->resource); + } + $this->resource=null; + } + + public function __destruct(){ + $this->destroy(); + } } |