diff --git a/.hgignore b/.hgignore
index 5c118c1e..822d53ff 100644
--- a/.hgignore
+++ b/.hgignore
@@ -1,2 +1,3 @@
syntax: glob
media/*
+tmp/*
diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc
index 5b5a7558..9077da8f 100644
--- a/configs/AppConfig.inc
+++ b/configs/AppConfig.inc
@@ -61,7 +61,8 @@
public static $dirs = array(
'locale' => 'locale',
'media' => 'media',
- 'questtypes' => 'questtypes'
+ 'questtypes' => 'questtypes',
+ 'temporary' => 'tmp'
);
@@ -86,8 +87,7 @@
array('characters/(?!(index|character))', 'characters/index/$1', true),
array('charactergroups/(?!(index|groupsgroup|group))', 'charactergroups/index/$1', true),
array('charactergroupsquests/(?!(quest))', 'charactergroupsquests/quest/$1', true),
- array('media/(.*)', 'media/$1?layout=binary', false),
- array('media/(.*)', 'media/index/$1', true)
+ array('media/(.*)', 'media/$1?layout=binary', false)
);
@@ -104,8 +104,7 @@
//array('seminaries/seminary/(.*)', '$1', false)
array('characters/index/(.*)', 'characters/$1', true),
array('charactergroup/index/(.*)', 'charactergroup/$1', true),
- array('charactergroupsquests/quest/(.*)', 'charactergroupsquests/$1', true),
- array('media/index/(.*)', 'media/$1', true)
+ array('charactergroupsquests/quest/(.*)', 'charactergroupsquests/$1', true)
);
diff --git a/controllers/MediaController.inc b/controllers/MediaController.inc
index aa69e704..897f2701 100644
--- a/controllers/MediaController.inc
+++ b/controllers/MediaController.inc
@@ -72,7 +72,7 @@
* @param string $seminaryUrl URL-title of the Seminary
* @param string $mediaUrl URL-name of the medium
*/
- public function index($seminaryUrl, $mediaUrl)
+ public function index($seminaryUrl, $mediaUrl, $action=null)
{
// Get Seminary
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
@@ -80,6 +80,10 @@
// Get Media
$media = $this->Media->getMediaByUrl($seminary['id'], $mediaUrl);
+ // Get format
+ $format = explode('/', $media['mimetype']);
+ $format = $format[1];
+
// Set content-type
$this->response->addHeader("Content-type: ".$media['mimetype']."");
@@ -94,9 +98,38 @@
return;
}
+ // Load and process file
+ $file = null;
+ switch($action)
+ {
+ // No action
+ case null:
+ // Do not process the file
+ $file = file_get_contents($media['filename']);
+ break;
+ case 'questgroup':
+ if(!in_array(strtoupper($format), static::getImageTypes())) {
+ $file = file_get_contents($media['filename']);
+ }
+ else
+ {
+ $file = static::resizeImage(
+ $media['filename'],
+ $format,
+ 480
+ );
+ }
+ break;
+ default:
+ throw new ParamsNotValidException($action);
+ break;
+ }
+
+
// Pass data to view
$this->set('media', $media);
+ $this->set('file', $file);
}
@@ -138,6 +171,70 @@
return false;
}
+
+
+
+ /**
+ * Get supported image types.
+ *
+ * @return array List of supported image types
+ */
+ private static function getImageTypes()
+ {
+ $im = new \Imagick();
+
+
+ return $im->queryFormats();
+ }
+
+
+ /**
+ * Resize an image.
+ *
+ * @param string $fileName Absolute pathname of image to resize
+ * @param string $mimeType Mimetype of target image
+ * @param int $size New size to resize to
+ */
+ private static function resizeImage($fileName, $mimeType, $size)
+ {
+ // Read image from cache
+ $tempFileName = ROOT.DS.\nre\configs\AppConfig::$dirs['temporary'].DS.'media-'.basename($fileName).'-'.$size;
+ if(file_exists($tempFileName))
+ {
+ // Check age of file
+ if(date('r', filemtime($tempFileName)+(60*60*24)) > date('r', time())) {
+ // Too old, delete
+ unlink($tempFileName);
+ }
+ else {
+ // Valid, read and return
+ return file_get_contents($tempFileName);
+ }
+ }
+
+
+ // ImageMagick
+ $im = new \Imagick($fileName);
+
+ // Calculate new size
+ $geometry = $im->getImageGeometry();
+ if($geometry['width'] < $size) {
+ $size = $geometry['width'];
+ }
+
+ // Process
+ $im->thumbnailImage($size, 5000, true);
+ $im->contrastImage(1);
+ $im->setImageFormat($mimeType);
+
+ // Save temporary file
+ $im->writeImage($tempFileName);
+
+
+ // Return resized image
+ return $im;
+ }
+
}
?>
diff --git a/controllers/QuestgroupsController.inc b/controllers/QuestgroupsController.inc
index 7ae4bd72..8657bf89 100644
--- a/controllers/QuestgroupsController.inc
+++ b/controllers/QuestgroupsController.inc
@@ -108,15 +108,18 @@
if(count($childQuestgroupshierarchy) == 0)
{
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
- for($i=0; $i =$group['character_xps']?> / =$group['xps']?> XP =\hhu\z\Utils::t($seminary['description'])?>=_('Seminaries')?>
-=$seminary['title']?>
+=$seminary['title']?>
=$questgroupshierarchypath?>
=$questgroupspicture?>
@@ -19,12 +18,12 @@
=_('Quests')?>
-
- =_('containing optional Quests')?>:
-
+
-
- =_('locked')?>
+ =_('locked')?>
=_('Seminaries')?>
-=$seminary['title']?>
+=$seminary['title']?>
=_('Description')?>
=$group['character_xps']?> / =$group['xps']?> XP