Skip to content

Commit

Permalink
Automatically resize organ images (fixes #525)
Browse files Browse the repository at this point in the history
  • Loading branch information
jszanto committed Jan 6, 2017
1 parent a0a3969 commit 2d262fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
7 changes: 7 additions & 0 deletions config/autoload/global.php
Expand Up @@ -120,6 +120,13 @@
]
],

'organ_information' => [
'cover_width' => 2000,
'cover_height' => 625,
'thumbnail_width' => 512,
'thumbnail_height' => 288,
],

'frontpage' => [
'activity_count' => 3, // Number of activities to display
'news_count' => 3, // Number of news items to display
Expand Down
34 changes: 27 additions & 7 deletions module/Decision/src/Decision/Service/Organ.php
Expand Up @@ -153,13 +153,16 @@ public function updateOrganInformation($organId, $post, $files)
return false;
}

$config = $this->getConfig();
if ($files['cover']['size'] > 0) {
$coverPath = $this->makeOrganInformationImage(
$files['cover']['tmp_name'],
$data['coverCropX'],
$data['coverCropY'],
$data['coverCropWidth'],
$data['coverCropHeight']
$data['coverCropHeight'],
$config['cover_width'],
$config['cover_height']
);
var_dump($coverPath);
$organInformation->setCoverPath($coverPath);
Expand All @@ -171,7 +174,9 @@ public function updateOrganInformation($organId, $post, $files)
$data['thumbnailCropX'],
$data['thumbnailCropY'],
$data['thumbnailCropWidth'],
$data['thumbnailCropHeight']
$data['thumbnailCropHeight'],
$config['thumbnail_width'],
$config['thumbnail_height']
);
$organInformation->setThumbnailPath($thumbnailPath);
}
Expand All @@ -186,7 +191,7 @@ public function updateOrganInformation($organId, $post, $files)
'Een orgaan heeft een update doorgevoerd | An organ has updated her page',
['organInfo' => $organInformation]);

return true;
return false;
}

/**
Expand All @@ -195,20 +200,23 @@ public function updateOrganInformation($organId, $post, $files)
* @param string $file The file to create the thumbnail of
* @param string $x The start x position in the image
* @param string $y The start y position in the image
* @param string $width The width of the thumbnail
* @param string $height The height of the thumbnail
* @param string $width The width of the area to crop
* @param string $height The height of the are to crop
* @param int $thumbWidth The width of the final thumbnail
* @param int $thumbHeight The height of the final thumbnail
* @return string path of where the thumbnail is stored
*/
public function makeOrganInformationImage($file, $x, $y, $width, $height)
public function makeOrganInformationImage($file, $x, $y, $width, $height, $thumbWidth, $thumbHeight)
{
$size = getimagesize($file);
$x = round($x * $size[0]);
$y = round($y * $size[1]);
$width = round($width * $size[0]);
$height = round($height * $size[1]);

var_dump($width,$height);
$image = new Imagick($file);
$image->cropImage($width, $height, $x, $y);
$image->thumbnailImage($thumbWidth, $thumbHeight);
$image->setimageformat('jpg');

//Tempfile is used to generate sha1ot sure this is the best method
Expand Down Expand Up @@ -380,6 +388,18 @@ public function getEntityManager()
return $this->sm->get('doctrine.entitymanager.orm_default');
}

/**
* Get the organ information config, as used by this service.
*
* @return array containing the config for the module
*/
public function getConfig()
{
$config = $this->sm->get('config');

return $config['organ_information'];
}

/**
* Get the default resource ID.
*
Expand Down

0 comments on commit 2d262fe

Please sign in to comment.