#779 remove image hover and center thumbnail

This commit is contained in:
BlueTeck
2015-04-09 09:01:29 +02:00
parent 4460851615
commit c1329ac7c4
4 changed files with 40 additions and 21 deletions

View File

@@ -112,6 +112,7 @@ class File extends Base
$file = $this->file->getById($this->request->getIntegerParam('file_id'));
$width_param = $this->request->getIntegerParam('width');
$height_param = $this->request->getIntegerParam('height');
$resize_cut_param = $this->request->getIntegerParam('resize_cut');
$filename = FILES_DIR.$file['path'];
if ($file['task_id'] == $task['id'] && file_exists($filename)) {
@@ -119,22 +120,46 @@ class File extends Base
// 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));
} elseif ($width_param == 0 && $height_param > 0) {
$newwidth = floor($width * ($height_param / $height));
$newheight = $height_param;
if($resize_cut_param == 0){
//resize without cut
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));
} elseif ($width_param == 0 && $height_param > 0) {
$newwidth = floor($width * ($height_param / $height));
$newheight = $height_param;
} else {
$newwidth = $width_param;
$newheight = $height_param;
}
$dest_y = 0;
$dest_x = 0;
$thumb = imagecreatetruecolor($newwidth, $newheight);
} else {
$newwidth = $width_param;
$newheight = $height_param;
// 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;
}
$thumb = imagecreatetruecolor($width_param, $height_param);
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
// Load
$extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
switch ($extension) {
@@ -154,7 +179,7 @@ class File extends Base
}
// Resize
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresampled($thumb, $source, $dest_x, $dest_y, 0, 0, $newwidth, $newheight, $width, $height);
$metadata = getimagesize($filename);