summaryrefslogtreecommitdiffstats
path: root/lib/image.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-03-26 23:53:48 +0200
committerRobin Appelman <icewind@owncloud.com>2012-03-26 23:53:48 +0200
commit73c6db5c8e6d876adf7b6c1c91049c66be26ba87 (patch)
tree2da6d0e783748b0c9d327ed0a3bdba044b7b8751 /lib/image.php
parent3f881f1ca50b50bb1d564c6bdf55789cda10d4d4 (diff)
downloadnextcloud-server-73c6db5c8e6d876adf7b6c1c91049c66be26ba87.tar.gz
nextcloud-server-73c6db5c8e6d876adf7b6c1c91049c66be26ba87.zip
crop and resize in a single step when creating thumbnail
also so more explicit memory cleanup
Diffstat (limited to 'lib/image.php')
-rw-r--r--lib/image.php26
1 files changed, 20 insertions, 6 deletions
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();
}
}