summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-04-11 13:47:31 -0400
committerFrederic Guillot <fred@kanboard.net>2015-04-11 13:47:31 -0400
commit3311061d10f94048c933a1beb3a3e7c408b40fcb (patch)
tree5625346bbbfdb236325d9815d80e7238b651d612 /app/Controller
parentaea3a352aa3a821c5c671e29bd730af79ab599eb (diff)
Improve pull-request (move thumbnail generation function)
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/File.php78
1 files changed, 6 insertions, 72 deletions
diff --git a/app/Controller/File.php b/app/Controller/File.php
index 00ab49bf..cc326dcd 100644
--- a/app/Controller/File.php
+++ b/app/Controller/File.php
@@ -110,82 +110,16 @@ class File extends Base
{
$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'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
- // Get new sizes
- list($width, $height) = getimagesize($filename);
-
- //default size
- if ($width_param == 0 && $height_param == 0) {
- $width_param = 100;
- $height_param = 100;
- }
-
- if ($width_param > 0 && $height_param == 0) {
- $newwidth = $width_param;
- $newheight = floor($height * ($width_param / $width));
- $dest_y = 0;
- $dest_x = 0;
- $thumb = imagecreatetruecolor($newwidth, $newheight);
- } elseif ($width_param == 0 && $height_param > 0) {
- $newwidth = floor($width * ($height_param / $height));
- $newheight = $height_param;
- $dest_y = 0;
- $dest_x = 0;
- $thumb = imagecreatetruecolor($newwidth, $newheight);
- } else {
- // resize and cut
- $ratio_img = $width / $height;
- $ratio_param = $width_param / $height_param;
-
- if($ratio_img <= $ratio_param){
- $newwidth = $width_param;
- $newheight = floor($height * ($width_param / $width));
-
- $dest_y = ( $newheight - $height_param ) / 2 * (-1);
- $dest_x = 0;
- }elseif($ratio_img > $ratio_param){
- $newwidth = floor($width * ($height_param / $height));
- $newheight = $height_param;
-
- $dest_y = 0;
- $dest_x = ( $newwidth - $width_param ) / 2 * (-1);
- }
- $thumb = imagecreatetruecolor($width_param, $height_param);
- }
-
- // Load
- $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
-
- switch ($extension) {
- case 'jpeg':
- case 'jpg':
- $source = imagecreatefromjpeg($filename);
- break;
- case 'png':
- $source = imagecreatefrompng($filename);
- break;
- case 'gif':
- $source = imagecreatefromgif($filename);
- break;
- default:
- die('File "' . $filename . '" is not valid jpg, png or gif image.');
- break;
- }
-
- // Resize
- imagecopyresampled($thumb, $source, $dest_x, $dest_y, 0, 0, $newwidth, $newheight, $width, $height);
-
- $metadata = getimagesize($filename);
-
- if (isset($metadata['mime'])) {
- $this->response->contentType($metadata['mime']);
- imagejpeg($thumb);
- }
+ $this->response->contentType('image/jpeg');
+ $this->file->generateThumbnail(
+ $filename,
+ $this->request->getIntegerParam('width'),
+ $this->request->getIntegerParam('height')
+ );
}
}