Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
AbstractBackgroundLayer | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
createSeed | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getAccentColor | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * Abstract cover background layer |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Cover_Generator |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Cover\Layer; |
31 | |
32 | use function ord; |
33 | use function strlen; |
34 | |
35 | /** |
36 | * Abstract cover background layer |
37 | * |
38 | * @category VuFind |
39 | * @package Cover_Generator |
40 | * @author Demian Katz <demian.katz@villanova.edu> |
41 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
42 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
43 | */ |
44 | abstract class AbstractBackgroundLayer extends AbstractLayer |
45 | { |
46 | /** |
47 | * Generates a dynamic cover image from elements of the book |
48 | * |
49 | * @param string $title Title of the book |
50 | * @param string $callnumber Callnumber of the book |
51 | * |
52 | * @return int unique number for this record |
53 | */ |
54 | protected function createSeed($title, $callnumber) |
55 | { |
56 | // Turn callnumber into number |
57 | if (null == $callnumber) { |
58 | $callnumber = $title; |
59 | } |
60 | if (null !== $callnumber) { |
61 | $cv = 0; |
62 | for ($i = 0; $i < strlen($callnumber); $i++) { |
63 | $cv += ord($callnumber[$i]); |
64 | } |
65 | return $cv; |
66 | } else { |
67 | // If no callnumber, random |
68 | return ceil(rand(2 ** 4, 2 ** 32)); |
69 | } |
70 | } |
71 | |
72 | /** |
73 | * Generate an accent color from a seed value. |
74 | * |
75 | * @param resource $im Active image resource |
76 | * @param int $seed Seed value |
77 | * @param object $settings Generator settings object |
78 | * |
79 | * @return int |
80 | */ |
81 | protected function getAccentColor($im, $seed, $settings) |
82 | { |
83 | // Number to color, hsb to control saturation and lightness |
84 | return $settings->accentColor == 'random' |
85 | ? $this->getHSBColor( |
86 | $im, |
87 | $seed % 256, |
88 | $settings->saturation, |
89 | $settings->lightness |
90 | ) : $this->getColor($im, $settings->accentColor); |
91 | } |
92 | } |