summaryrefslogtreecommitdiff
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
parentaea3a352aa3a821c5c671e29bd730af79ab599eb (diff)
Improve pull-request (move thumbnail generation function)
-rw-r--r--app/Controller/File.php78
-rw-r--r--app/Locale/da_DK/translations.php3
-rw-r--r--app/Locale/de_DE/translations.php3
-rw-r--r--app/Locale/es_ES/translations.php3
-rw-r--r--app/Locale/fi_FI/translations.php3
-rw-r--r--app/Locale/fr_FR/translations.php3
-rw-r--r--app/Locale/hu_HU/translations.php3
-rw-r--r--app/Locale/it_IT/translations.php3
-rw-r--r--app/Locale/ja_JP/translations.php3
-rw-r--r--app/Locale/nl_NL/translations.php3
-rw-r--r--app/Locale/pl_PL/translations.php3
-rw-r--r--app/Locale/pt_BR/translations.php3
-rw-r--r--app/Locale/ru_RU/translations.php3
-rw-r--r--app/Locale/sr_Latn_RS/translations.php3
-rw-r--r--app/Locale/sv_SE/translations.php3
-rw-r--r--app/Locale/th_TH/translations.php3
-rw-r--r--app/Locale/tr_TR/translations.php3
-rw-r--r--app/Locale/zh_CN/translations.php3
-rw-r--r--app/Model/File.php86
-rw-r--r--app/Schema/Mysql.php6
-rw-r--r--app/Schema/Postgres.php6
-rw-r--r--app/Schema/Sqlite.php6
-rw-r--r--app/Template/file/show.php4
23 files changed, 149 insertions, 88 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')
+ );
}
}
diff --git a/app/Locale/da_DK/translations.php b/app/Locale/da_DK/translations.php
index 2f83ac8b..2e543e48 100644
--- a/app/Locale/da_DK/translations.php
+++ b/app/Locale/da_DK/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/de_DE/translations.php b/app/Locale/de_DE/translations.php
index f76c5903..55800071 100644
--- a/app/Locale/de_DE/translations.php
+++ b/app/Locale/de_DE/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/es_ES/translations.php b/app/Locale/es_ES/translations.php
index 738523a0..f0a2ef4c 100644
--- a/app/Locale/es_ES/translations.php
+++ b/app/Locale/es_ES/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/fi_FI/translations.php b/app/Locale/fi_FI/translations.php
index 22dcaab1..48a38f46 100644
--- a/app/Locale/fi_FI/translations.php
+++ b/app/Locale/fi_FI/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/fr_FR/translations.php b/app/Locale/fr_FR/translations.php
index d0d890d6..a99e19ae 100644
--- a/app/Locale/fr_FR/translations.php
+++ b/app/Locale/fr_FR/translations.php
@@ -849,4 +849,7 @@ return array(
'Test your device' => 'Testez votre appareil',
'Assign a color when the task is moved to a specific column' => 'Assigner une couleur lorsque la tâche est déplacée dans une colonne spécifique',
'%s via Kanboard' => '%s via Kanboard',
+ 'uploaded by: %s' => 'Télécharger par : %s',
+ 'uploaded on: %s' => 'Télécharger le : %s',
+ 'size: %s' => 'Taille : %s',
);
diff --git a/app/Locale/hu_HU/translations.php b/app/Locale/hu_HU/translations.php
index 38829773..f398629e 100644
--- a/app/Locale/hu_HU/translations.php
+++ b/app/Locale/hu_HU/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/it_IT/translations.php b/app/Locale/it_IT/translations.php
index b3a31001..d034ce94 100644
--- a/app/Locale/it_IT/translations.php
+++ b/app/Locale/it_IT/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/ja_JP/translations.php b/app/Locale/ja_JP/translations.php
index c8d85d11..9cedf534 100644
--- a/app/Locale/ja_JP/translations.php
+++ b/app/Locale/ja_JP/translations.php
@@ -847,4 +847,7 @@ return array(
'Test your device' => 'デバイスをテストする',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/nl_NL/translations.php b/app/Locale/nl_NL/translations.php
index bf362916..31a8006c 100644
--- a/app/Locale/nl_NL/translations.php
+++ b/app/Locale/nl_NL/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/pl_PL/translations.php b/app/Locale/pl_PL/translations.php
index e72bcb16..8dee492e 100644
--- a/app/Locale/pl_PL/translations.php
+++ b/app/Locale/pl_PL/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/pt_BR/translations.php b/app/Locale/pt_BR/translations.php
index a4088576..f855edb0 100644
--- a/app/Locale/pt_BR/translations.php
+++ b/app/Locale/pt_BR/translations.php
@@ -847,4 +847,7 @@ return array(
'Test your device' => 'Teste o seu dispositivo',
'Assign a color when the task is moved to a specific column' => 'Atribuir uma cor quando a tarefa é movida em uma coluna específica',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/ru_RU/translations.php b/app/Locale/ru_RU/translations.php
index 9d9388ef..d67de097 100644
--- a/app/Locale/ru_RU/translations.php
+++ b/app/Locale/ru_RU/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/sr_Latn_RS/translations.php b/app/Locale/sr_Latn_RS/translations.php
index 1308857f..26a3599a 100644
--- a/app/Locale/sr_Latn_RS/translations.php
+++ b/app/Locale/sr_Latn_RS/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/sv_SE/translations.php b/app/Locale/sv_SE/translations.php
index 42c3957b..90de7470 100644
--- a/app/Locale/sv_SE/translations.php
+++ b/app/Locale/sv_SE/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/th_TH/translations.php b/app/Locale/th_TH/translations.php
index 4d31fb0d..f48999cb 100644
--- a/app/Locale/th_TH/translations.php
+++ b/app/Locale/th_TH/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/tr_TR/translations.php b/app/Locale/tr_TR/translations.php
index 2337d5bf..fb8bc080 100644
--- a/app/Locale/tr_TR/translations.php
+++ b/app/Locale/tr_TR/translations.php
@@ -847,4 +847,7 @@ return array(
// 'Test your device' => '',
// 'Assign a color when the task is moved to a specific column' => '',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Locale/zh_CN/translations.php b/app/Locale/zh_CN/translations.php
index 4d116a46..10d4c604 100644
--- a/app/Locale/zh_CN/translations.php
+++ b/app/Locale/zh_CN/translations.php
@@ -847,4 +847,7 @@ return array(
'Test your device' => '测试设备',
'Assign a color when the task is moved to a specific column' => '任务移动到指定栏目时设置颜色',
// '%s via Kanboard' => '',
+ // 'uploaded by: %s' => '',
+ // 'uploaded on: %s' => '',
+ // 'size: %s' => '',
);
diff --git a/app/Model/File.php b/app/Model/File.php
index 52f756c6..5da5c014 100644
--- a/app/Model/File.php
+++ b/app/Model/File.php
@@ -80,6 +80,7 @@ class File extends Base
* @param string $name Filename
* @param string $path Path on the disk
* @param bool $is_image Image or not
+ * @param integer $size File size
* @return bool
*/
public function create($task_id, $name, $path, $is_image, $size)
@@ -96,7 +97,7 @@ class File extends Base
'is_image' => $is_image ? '1' : '0',
'size' => $size,
'user_id' => $this->userSession->getId(),
- 'date' => time(),
+ 'date' => time(),
));
}
@@ -122,11 +123,11 @@ class File extends Base
self::TABLE.'.size',
User::TABLE.'.username',
User::TABLE.'.name as user_name'
- )
+ )
->join(User::TABLE, 'id', 'user_id')
->eq('task_id', $task_id)
- ->asc(self::TABLE.'.name')
- ->findAll();
+ ->asc(self::TABLE.'.name')
+ ->findAll();
}
/**
@@ -276,7 +277,7 @@ class File extends Base
$original_filename,
$destination_filename,
$this->isImage($original_filename),
- $_FILES[$form_name]['size'][$key]
+ $_FILES[$form_name]['size'][$key]
);
}
}
@@ -285,4 +286,79 @@ class File extends Base
return count(array_unique($result)) === 1;
}
+
+ /**
+ * Generate a jpeg thumbnail from an image (output directly the image)
+ *
+ * @access public
+ * @param string $filename Source image
+ * @param integer $resize_width Desired image width
+ * @param integer $resize_height Desired image height
+ */
+ public function generateThumbnail($filename, $resize_width, $resize_height)
+ {
+ $metadata = getimagesize($filename);
+ $src_width = $metadata[0];
+ $src_height = $metadata[1];
+ $dst_y = 0;
+ $dst_x = 0;
+
+ if (empty($metadata['mime'])) {
+ return;
+ }
+
+ if ($resize_width == 0 && $resize_height == 0) {
+ $resize_width = 100;
+ $resize_height = 100;
+ }
+
+ if ($resize_width > 0 && $resize_height == 0) {
+ $dst_width = $resize_width;
+ $dst_height = floor($src_height * ($resize_width / $src_width));
+ $dst_image = imagecreatetruecolor($dst_width, $dst_height);
+ }
+ elseif ($resize_width == 0 && $resize_height > 0) {
+ $dst_width = floor($src_width * ($resize_height / $src_height));
+ $dst_height = $resize_height;
+ $dst_image = imagecreatetruecolor($dst_width, $dst_height);
+ }
+ else {
+
+ $src_ratio = $src_width / $src_height;
+ $resize_ratio = $resize_width / $resize_height;
+
+ if ($src_ratio <= $resize_ratio) {
+ $dst_width = $resize_width;
+ $dst_height = floor($src_height * ($resize_width / $src_width));
+
+ $dst_y = ($dst_height - $resize_height) / 2 * (-1);
+ }
+ else {
+ $dst_width = floor($src_width * ($resize_height / $src_height));
+ $dst_height = $resize_height;
+
+ $dst_x = ($dst_width - $resize_width) / 2 * (-1);
+ }
+
+ $dst_image = imagecreatetruecolor($resize_width, $resize_height);
+ }
+
+ switch ($metadata['mime']) {
+ case 'image/jpeg':
+ case 'image/jpg':
+ $src_image = imagecreatefromjpeg($filename);
+ break;
+ case 'image/png':
+ $src_image = imagecreatefrompng($filename);
+ break;
+ case 'image/gif':
+ $src_image = imagecreatefromgif($filename);
+ break;
+ default:
+ return;
+ }
+
+ imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
+ imagejpeg($dst_image);
+ }
}
diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php
index 626f7b84..91e744a4 100644
--- a/app/Schema/Mysql.php
+++ b/app/Schema/Mysql.php
@@ -10,9 +10,9 @@ const VERSION = 62;
function version_62($pdo)
{
- $pdo->exec('ALTER TABLE files ADD COLUMN date VARCHAR(10) NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN user_id INT NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN size FLOAT NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN `date` INT NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN `user_id` INT NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN `size` INT NOT NULL DEFAULT 0');
}
function version_61($pdo)
diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php
index 4b9752eb..0c4c4829 100644
--- a/app/Schema/Postgres.php
+++ b/app/Schema/Postgres.php
@@ -10,9 +10,9 @@ const VERSION = 43;
function version_43($pdo)
{
- $pdo->exec('ALTER TABLE files ADD COLUMN date VARCHAR(10) NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN user_id INT NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN size FLOAT NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "date" INTEGER NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "user_id" INTEGER NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0');
}
function version_42($pdo)
diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php
index 52a37d25..4ea1f875 100644
--- a/app/Schema/Sqlite.php
+++ b/app/Schema/Sqlite.php
@@ -10,9 +10,9 @@ const VERSION = 61;
function version_61($pdo)
{
- $pdo->exec('ALTER TABLE files ADD COLUMN date VARCHAR(10) NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN user_id INT NOT NULL DEFAULT 0');
- $pdo->exec('ALTER TABLE files ADD COLUMN size FLOAT NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "date" INTEGER NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "user_id" INTEGER NOT NULL DEFAULT 0');
+ $pdo->exec('ALTER TABLE files ADD COLUMN "size" INTEGER NOT NULL DEFAULT 0');
}
function version_60($pdo)
diff --git a/app/Template/file/show.php b/app/Template/file/show.php
index eea4a3f6..3ce7f9f4 100644
--- a/app/Template/file/show.php
+++ b/app/Template/file/show.php
@@ -16,7 +16,7 @@
<?php endif ?>
<p>
<?= $this->e($file['name']) ?>
- <span class="column-tooltip" title='<?= $this->e(t('uploaded by').': '.$this->e($file['user_name'] ?: $file['username']).'<br>'.t('uploaded on').': '.dt('%B %e, %Y at %k:%M %p', $file['date']).'<br>'.t('size').': '.round($file['size']/1024/1024,2)).' MB' ?>'>
+ <span class="column-tooltip" title='<?= t('uploaded by: %s', $file['user_name'] ?: $file['username']).'<br>'.t('uploaded on: %s', dt('%B %e, %Y at %k:%M %p', $file['date'])).'<br>'.t('size: %s', $this->formatBytes($file['size'])) ?>'>
<i class="fa fa-info-circle"></i>
</span>
</p>
@@ -38,7 +38,7 @@
<td><i class="fa <?= $this->getFileIcon($file['name']) ?> fa-fw"></i></td>
<td>
<?= $this->e($file['name']) ?>
- <span class="column-tooltip" title='<?= $this->e(t('uploaded by').': '.$this->e($file['user_name'] ?: $file['username']).'<br>'.t('uploaded on').': '.dt('%B %e, %Y at %k:%M %p', $file['date']).'<br>'.t('size').': '.round($file['size']/1024/1024,2)).' MB' ?>'>
+ <span class="column-tooltip" title='<?= t('uploaded by: %s', $file['user_name'] ?: $file['username']).'<br>'.t('uploaded on: %s', dt('%B %e, %Y at %k:%M %p', $file['date'])).'<br>'.t('size: %s', $this->formatBytes($file['size'])) ?>'>
<i class="fa fa-info-circle"></i>
</span>
</td>