1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00
phorge-phorge/src/applications/lipsum/image/PhabricatorLipsumArtist.php

69 lines
1.3 KiB
PHP
Raw Normal View History

<?php
abstract class PhabricatorLipsumArtist {
protected function getHSBColor($h, $s, $b) {
if ($s == 0) {
$cr = $b;
$cg = $b;
$cb = $b;
} else {
$h /= 60;
$i = (int)$h;
$f = $h - $i;
$p = $b * (1 - $s);
$q = $b * (1 - $s * $f);
$t = $b * (1 - $s * (1 - $f));
switch ($i) {
case 0:
$cr = $b;
$cg = $t;
$cb = $p;
break;
case 1:
$cr = $q;
$cg = $b;
$cb = $p;
break;
case 2:
$cr = $p;
$cg = $b;
$cb = $t;
break;
case 3:
$cr = $p;
$cg = $q;
$cb = $b;
break;
case 4:
$cr = $t;
$cg = $p;
$cb = $b;
break;
default:
$cr = $b;
$cg = $p;
$cb = $q;
break;
}
}
$cr = (int)round($cr * 255);
$cg = (int)round($cg * 255);
$cb = (int)round($cb * 255);
return ($cr << 16) + ($cg << 8) + $cb;
}
public function generate($x, $y) {
$image = imagecreatetruecolor($x, $y);
$this->draw($image, $x, $y);
return PhabricatorImageTransformer::saveImageDataInAnyFormat(
$image,
'image/jpeg');
}
abstract protected function draw($image, $x, $y);
}