diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-06-02 15:25:50 +0200 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-06-10 13:15:23 +0200 |
commit | 9b2b5e0f6d61b39128d7a2f33b8690ec2b8ae75c (patch) | |
tree | 0b782afdfd9f2f09e32f4820618d74ac20340c58 /lib | |
parent | be6848a549d9d5c5fdc224dfd1e22a416d8048a7 (diff) | |
download | nextcloud-server-9b2b5e0f6d61b39128d7a2f33b8690ec2b8ae75c.tar.gz nextcloud-server-9b2b5e0f6d61b39128d7a2f33b8690ec2b8ae75c.zip |
git status
Diffstat (limited to 'lib')
-rw-r--r-- | lib/image.php | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/image.php b/lib/image.php index 4c53dc32f58..3150631cc34 100644 --- a/lib/image.php +++ b/lib/image.php @@ -136,6 +136,8 @@ class OC_Image { */ private function _output($filepath=null) { if($filepath) { + if (!file_exists(dirname($filepath))) + mkdir(dirname($filepath), 0777, true); if(!is_writable(dirname($filepath))) { OC_Log::write('core',__METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR); return false; @@ -419,7 +421,7 @@ class OC_Image { if(is_resource($str)) { return false; } - $this->resource = imagecreatefromstring($str); + $this->resource = @imagecreatefromstring($str); if(!$this->resource) { OC_Log::write('core','OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); return false; @@ -438,7 +440,7 @@ class OC_Image { } $data = base64_decode($str); if($data) { // try to load from string data - $this->resource = imagecreatefromstring($data); + $this->resource = @imagecreatefromstring($data); if(!$this->resource) { OC_Log::write('core','OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG); return false; @@ -489,6 +491,32 @@ class OC_Image { return true; } + public function preciseResize($width, $height) { + if (!$this->valid()) { + OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); + return false; + } + $width_orig=imageSX($this->resource); + $height_orig=imageSY($this->resource); + $process = imagecreatetruecolor($width, $height); + + if ($process == false) { + OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR); + imagedestroy($process); + return false; + } + + imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); + if ($process == false) { + OC_Log::write('core',__METHOD__.'(): Error resampling process image '.$width.'x'.$height,OC_Log::ERROR); + 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) |