Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / lipsum / image / PhabricatorLipsumArtist.php
blob06bedcd693b25a2d57e8174b3f83b3a4fcbac54e
1 <?php
3 abstract class PhabricatorLipsumArtist extends Phobject {
5 protected function getHSBColor($h, $s, $b) {
6 if ($s == 0) {
7 $cr = $b;
8 $cg = $b;
9 $cb = $b;
10 } else {
11 $h /= 60;
12 $i = (int)$h;
13 $f = $h - $i;
14 $p = $b * (1 - $s);
15 $q = $b * (1 - $s * $f);
16 $t = $b * (1 - $s * (1 - $f));
17 switch ($i) {
18 case 0:
19 $cr = $b;
20 $cg = $t;
21 $cb = $p;
22 break;
23 case 1:
24 $cr = $q;
25 $cg = $b;
26 $cb = $p;
27 break;
28 case 2:
29 $cr = $p;
30 $cg = $b;
31 $cb = $t;
32 break;
33 case 3:
34 $cr = $p;
35 $cg = $q;
36 $cb = $b;
37 break;
38 case 4:
39 $cr = $t;
40 $cg = $p;
41 $cb = $b;
42 break;
43 default:
44 $cr = $b;
45 $cg = $p;
46 $cb = $q;
47 break;
51 $cr = (int)round($cr * 255);
52 $cg = (int)round($cg * 255);
53 $cb = (int)round($cb * 255);
55 return ($cr << 16) + ($cg << 8) + $cb;
58 public function generate($x, $y) {
59 $image = imagecreatetruecolor($x, $y);
60 $this->draw($image, $x, $y);
61 return PhabricatorImageTransformer::saveImageDataInAnyFormat(
62 $image,
63 'image/jpeg');
66 abstract protected function draw($image, $x, $y);