Simplify and correct thumbnail method
This commit is contained in:
@@ -112,7 +112,6 @@ class File extends Base
|
|||||||
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
|
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
|
||||||
$width_param = $this->request->getIntegerParam('width');
|
$width_param = $this->request->getIntegerParam('width');
|
||||||
$height_param = $this->request->getIntegerParam('height');
|
$height_param = $this->request->getIntegerParam('height');
|
||||||
$resize_cut_param = $this->request->getIntegerParam('resize_cut');
|
|
||||||
$filename = FILES_DIR.$file['path'];
|
$filename = FILES_DIR.$file['path'];
|
||||||
|
|
||||||
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
|
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
|
||||||
@@ -120,21 +119,21 @@ class File extends Base
|
|||||||
// Get new sizes
|
// Get new sizes
|
||||||
list($width, $height) = getimagesize($filename);
|
list($width, $height) = getimagesize($filename);
|
||||||
|
|
||||||
if($resize_cut_param == 0){
|
//default size
|
||||||
//resize without cut
|
if ($width_param == 0 && $height_param == 0) {
|
||||||
if ($width_param == 0 && $height_param == 0) {
|
$width_param = 100;
|
||||||
$newwidth = 100;
|
$height_param = 100;
|
||||||
$newheight = 100;
|
}
|
||||||
} elseif ($width_param > 0 && $height_param == 0) {
|
|
||||||
$newwidth = $width_param;
|
if ($width_param > 0 && $height_param == 0) {
|
||||||
$newheight = floor($height * ($width_param / $width));
|
$newwidth = $width_param;
|
||||||
} elseif ($width_param == 0 && $height_param > 0) {
|
$newheight = floor($height * ($width_param / $width));
|
||||||
$newwidth = floor($width * ($height_param / $height));
|
$dest_y = 0;
|
||||||
$newheight = $height_param;
|
$dest_x = 0;
|
||||||
} else {
|
$thumb = imagecreatetruecolor($newwidth, $newheight);
|
||||||
$newwidth = $width_param;
|
} elseif ($width_param == 0 && $height_param > 0) {
|
||||||
$newheight = $height_param;
|
$newwidth = floor($width * ($height_param / $height));
|
||||||
}
|
$newheight = $height_param;
|
||||||
$dest_y = 0;
|
$dest_y = 0;
|
||||||
$dest_x = 0;
|
$dest_x = 0;
|
||||||
$thumb = imagecreatetruecolor($newwidth, $newheight);
|
$thumb = imagecreatetruecolor($newwidth, $newheight);
|
||||||
@@ -143,7 +142,7 @@ class File extends Base
|
|||||||
$ratio_img = $width / $height;
|
$ratio_img = $width / $height;
|
||||||
$ratio_param = $width_param / $height_param;
|
$ratio_param = $width_param / $height_param;
|
||||||
|
|
||||||
if($ratio_img < $ratio_param){
|
if($ratio_img <= $ratio_param){
|
||||||
$newwidth = $width_param;
|
$newwidth = $width_param;
|
||||||
$newheight = floor($height * ($width_param / $width));
|
$newheight = floor($height * ($width_param / $width));
|
||||||
|
|
||||||
@@ -154,7 +153,7 @@ class File extends Base
|
|||||||
$newheight = $height_param;
|
$newheight = $height_param;
|
||||||
|
|
||||||
$dest_y = 0;
|
$dest_y = 0;
|
||||||
$dest_x = ( $newwidth - $width_param ) / 2;
|
$dest_x = ( $newwidth - $width_param ) / 2 * (-1);
|
||||||
}
|
}
|
||||||
$thumb = imagecreatetruecolor($width_param, $height_param);
|
$thumb = imagecreatetruecolor($width_param, $height_param);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<li>
|
<li>
|
||||||
<?php if (function_exists('imagecreatetruecolor')): ?>
|
<?php if (function_exists('imagecreatetruecolor')): ?>
|
||||||
<div class="img_container">
|
<div class="img_container">
|
||||||
<img src="<?= $this->u('file', 'thumbnail', array('width' => 250, 'height' => 100, 'resize_cut' => 1, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/>
|
<img src="<?= $this->u('file', 'thumbnail', array('width' => 250, 'height' => 100, 'file_id' => $file['id'], 'project_id' => $task['project_id'], 'task_id' => $file['task_id'])) ?>" alt="<?= $this->e($file['name']) ?>"/>
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
Reference in New Issue
Block a user