Gitlab CSE Unil
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
M. Chardon
moodle-assignfeedback_editpdfplus
Commits
5f177a64
Commit
5f177a64
authored
Jun 05, 2018
by
M. Chardon
Browse files
optimisation generation stamps à la volée (contrôle existance et date de création)
parent
4171ba36
Changes
2
Hide whitespace changes
Inline
Side-by-side
classes/utils_color.php
View file @
5f177a64
...
...
@@ -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 $hexStr
Raw
(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
(
$hexStr
Raw
,
$returnAsString
=
false
,
$seperator
=
','
)
{
// Gets a proper hex string
$hexStr
=
preg_replace
(
"/[^0-9A-Fa-f]/"
,
''
,
$hexStr
);
$hexStr
=
preg_replace
(
"/[^0-9A-Fa-f]/"
,
''
,
$hexStr
Raw
);
$rgbArray
=
array
();
//If a proper hex code, convert using bitwise operation. No overhead... faster
if
(
strlen
(
$hexStr
)
==
6
)
{
...
...
classes/utils_stamp.php
View file @
5f177a64
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment