Gitlab CSE Unil

Commit 5f177a64 authored by M. Chardon's avatar M. Chardon
Browse files

optimisation generation stamps à la volée (contrôle existance et date de création)

parent 4171ba36
......@@ -58,14 +58,14 @@ class utils_color {
/**
* Convert a hexa decimal color code to its RGB equivalent
*
* @param string $hexStr (hexadecimal color value)
* @param string $hexStrRaw (hexadecimal color value)
* @param boolean $returnAsString (if set true, returns the value separated by the separator character. Otherwise returns associative array)
* @param string $seperator (to separate RGB values. Applicable only if second parameter is true.)
* @return array or string (depending on second parameter. Returns False if invalid hex color value)
*/
public static function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') {
public static function hex2RGB($hexStrRaw, $returnAsString = false, $seperator = ',') {
// Gets a proper hex string
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr);
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStrRaw);
$rgbArray = array();
//If a proper hex code, convert using bitwise operation. No overhead... faster
if (strlen($hexStr) == 6) {
......
......@@ -49,6 +49,9 @@ class utils_stamp {
/** File area for the stamps */
const STAMPS_FILEAREA = '/assignfeedback_editpdfplus/stamps/';
/** Number of months when the stamps should be renewed */
const REFRESH_TIME = 6;
/**
* Convert a FontAwesome icon into a PNG file
* Main method
......@@ -67,19 +70,29 @@ class utils_stamp {
return null;
}
//get RGB color
$colorRGB = utils_color::hex2RGB($color);
if (!$colorRGB) {
return null;
}
//create final file
$outputDirectory = $CFG->tempdir . self::STAMPS_FILEAREA;
$fileName = sprintf("%s%s.png", $outputDirectory, $iconName);
$fileName = sprintf("%s%s_%s-%s-%s_%s.png", $outputDirectory, $iconName, $colorRGB['red'], $colorRGB['green'], $colorRGB['blue'], $fontSize);
$dirPath = dirname($fileName);
if (!is_dir($dirPath) || !file_exists($dirPath)) {
//try to create the directory
self::mkdirRecursive($dirPath, 0777);
} else if (file_exists($fileName)) {
//check if the file is not too old
$lastDateRefresh = mktime(0, 0, 0, date("m") - self::REFRESH_TIME, date("d"), date("Y"));
$dateCreation = filemtime($fileName);
if ($lastDateRefresh < $dateCreation) {
return $fileName;
}
}
//get RGB color
$colorRGB = utils_color::hex2RGB($color);
//put image into file and return
return self::putIconIntoFile($charFAHexaCode, $fileName, $colorRGB, $fontSize);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment