From d91b5d4aa3acae17333eb7300bc0f6621dab11b2 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Tue, 10 Mar 2015 22:37:09 -0400 Subject: Improve pull-request --- app/Controller/File.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'app/Controller/File.php') diff --git a/app/Controller/File.php b/app/Controller/File.php index 1e719d2f..3963e2d7 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -20,8 +20,8 @@ class File extends Base $task = $this->getTask(); $this->response->html($this->taskLayout('file/new', array( - 'task' => $task, - 'max_size' => ini_get('upload_max_filesize'), + 'task' => $task, + 'max_size' => ini_get('upload_max_filesize'), ))); } @@ -74,8 +74,8 @@ class File extends Base if ($file['task_id'] == $task['id']) { $this->response->html($this->template->render('file/open', array( - 'file' => $file, - 'task' => $task, + 'file' => $file, + 'task' => $task, ))); } } @@ -102,29 +102,31 @@ class File extends Base } /** - * Return the file content (work only for images) resized + * Return image thumbnails * * @access public */ - public function imageThumbnail() { + public function thumbnail() + { $task = $this->getTask(); $file = $this->file->getById($this->request->getIntegerParam('file_id')); $width_param = $this->request->getIntegerParam('width'); $height_param = $this->request->getIntegerParam('height'); - $filename = FILES_DIR . $file['path']; + $filename = FILES_DIR.$file['path']; if ($file['task_id'] == $task['id'] && file_exists($filename)) { // Get new sizes list($width, $height) = getimagesize($filename); + if ($width_param == 0 && $height_param == 0) { $newwidth = 100; $newheight = 100; } elseif ($width_param > 0 && $height_param == 0) { $newwidth = $width_param; - $newheight = floor($height * ( $width_param / $width )); + $newheight = floor($height * ($width_param / $width)); } elseif ($width_param == 0 && $height_param > 0) { - $newwidth = floor($width * ( $height_param / $height )); + $newwidth = floor($width * ($height_param / $height)); $newheight = $height_param; } else { $newwidth = $width_param; @@ -133,9 +135,7 @@ class File extends Base // Load $thumb = imagecreatetruecolor($newwidth, $newheight); - - $info = pathinfo($file['name']); - $extension = strtolower($info['extension']); + $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); switch ($extension) { case 'jpeg': @@ -153,17 +153,18 @@ class File extends Base break; } - // Resize + // Resize imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $metadata = getimagesize($filename); + if (isset($metadata['mime'])) { $this->response->contentType($metadata['mime']); imagejpeg($thumb); } } } - + /** * Remove a file * @@ -195,8 +196,8 @@ class File extends Base $file = $this->file->getById($this->request->getIntegerParam('file_id')); $this->response->html($this->taskLayout('file/remove', array( - 'task' => $task, - 'file' => $file, + 'task' => $task, + 'file' => $file, ))); } } -- cgit v1.2.3