Bånder

BlurHash
in package

Table of Contents

Properties

$componentX  : int
$componentY  : int
$driver  : Driver
$rgbToLinearMap  : array<int, float>
RGB Value to Linear Map

Methods

__construct()  : mixed
Create a new BlurHash instance.
decode()  : object
Decode a BlurHash string to an image instance.
encode()  : string
Encode an image to BlurHash string.
normalizeComponent()  : int<1, 9>
Restrict component value between 1 and 9.
setComponentX()  : self
Set component x.
setComponentY()  : self
Set component y.
setMaxSize()  : self
Set resized image max width.
decodeAC()  : array<int, float>
encodeAC()  : int
Encode ac factor.
pow()  : float
quantise()  : int
toRGB()  : array<int, float>
toSRGB()  : int<0, 255>
transform()  : array<int, array<int, float>>
Magic transform function.

Properties

$rgbToLinearMap

RGB Value to Linear Map

public static array<int, float> $rgbToLinearMap = [0 => 0.0, 1 => 0.0003, 2 => 0.0005999999999999999, 3 => 0.0009, 4 => 0.0012, 5 => 0.0015, 6 => 0.0018, 7 => 0.0021, 8 => 0.0024, 9 => 0.0027, 10 => 0.003, 11 => 0.0033, 12 => 0.0036, 13 => 0.004, 14 => 0.0043, 15 => 0.0047, 16 => 0.0051, 17 => 0.0056, 18 => 0.006, 19 => 0.0065, 20 => 0.0069, 21 => 0.0074, 22 => 0.008, 23 => 0.008500000000000001, 24 => 0.0091, 25 => 0.0097, 26 => 0.0103, 27 => 0.0109, 28 => 0.0116, 29 => 0.0122, 30 => 0.0129, 31 => 0.0137, 32 => 0.0144, 33 => 0.0152, 34 => 0.0159, 35 => 0.0168, 36 => 0.0176, 37 => 0.0185, 38 => 0.0193, 39 => 0.0202, 40 => 0.0212, 41 => 0.0221, 42 => 0.0231, 43 => 0.0241, 44 => 0.0251, 45 => 0.0262, 46 => 0.0273, 47 => 0.0284, 48 => 0.0295, 49 => 0.0307, 50 => 0.0318, 51 => 0.0331, 52 => 0.0343, 53 => 0.0356, 54 => 0.0368, 55 => 0.0382, 56 => 0.0395, 57 => 0.0409, 58 => 0.0423, 59 => 0.0437, 60 => 0.0451, 61 => 0.0466, 62 => 0.0481, 63 => 0.0497, 64 => 0.0512, 65 => 0.0528, 66 => 0.0544, 67 => 0.0561, 68 => 0.0578, 69 => 0.0595, 70 => 0.0612, 71 => 0.063, 72 => 0.0648, 73 => 0.06660000000000001, 74 => 0.0684, 75 => 0.0703, 76 => 0.0722, 77 => 0.0742, 78 => 0.0761, 79 => 0.0781, 80 => 0.08019999999999999, 81 => 0.0822, 82 => 0.0843, 83 => 0.08649999999999999, 84 => 0.0886, 85 => 0.09080000000000001, 86 => 0.093, 87 => 0.0953, 88 => 0.0975, 89 => 0.0998, 90 => 0.1022, 91 => 0.1046, 92 => 0.107, 93 => 0.1094, 94 => 0.1119, 95 => 0.1144, 96 => 0.1169, 97 => 0.1195, 98 => 0.1221, 99 => 0.1247, 100 => 0.1274, 101 => 0.1301, 102 => 0.1328, 103 => 0.1356, 104 => 0.1384, 105 => 0.1412, 106 => 0.1441, 107 => 0.147, 108 => 0.1499, 109 => 0.1529, 110 => 0.1559, 111 => 0.1589, 112 => 0.162, 113 => 0.1651, 114 => 0.1682, 115 => 0.1714, 116 => 0.1746, 117 => 0.1778, 118 => 0.1811, 119 => 0.1844, 120 => 0.1878, 121 => 0.1912, 122 => 0.1946, 123 => 0.198, 124 => 0.2015, 125 => 0.205, 126 => 0.2086, 127 => 0.2122, 128 => 0.2158, 129 => 0.2195, 130 => 0.2232, 131 => 0.2269, 132 => 0.2307, 133 => 0.2345, 134 => 0.2383, 135 => 0.2422, 136 => 0.2462, 137 => 0.2501, 138 => 0.2541, 139 => 0.2581, 140 => 0.2622, 141 => 0.2663, 142 => 0.2704, 143 => 0.2746, 144 => 0.2788, 145 => 0.2831, 146 => 0.2874, 147 => 0.2917, 148 => 0.2961, 149 => 0.3005, 150 => 0.3049, 151 => 0.3094, 152 => 0.3139, 153 => 0.3185, 154 => 0.3231, 155 => 0.3277, 156 => 0.3324, 157 => 0.3371, 158 => 0.3419, 159 => 0.3467, 160 => 0.3515, 161 => 0.3564, 162 => 0.3613, 163 => 0.3662, 164 => 0.3712, 165 => 0.3762, 166 => 0.3813, 167 => 0.3864, 168 => 0.3915, 169 => 0.3967, 170 => 0.4019, 171 => 0.4072, 172 => 0.4125, 173 => 0.4178, 174 => 0.4232, 175 => 0.4286, 176 => 0.4341, 177 => 0.4396, 178 => 0.4452, 179 => 0.4507, 180 => 0.4564, 181 => 0.462, 182 => 0.4677, 183 => 0.4735, 184 => 0.4793, 185 => 0.4851, 186 => 0.491, 187 => 0.4969, 188 => 0.5028, 189 => 0.5088, 190 => 0.5149, 191 => 0.5209, 192 => 0.5271, 193 => 0.5332, 194 => 0.5394, 195 => 0.5457, 196 => 0.552, 197 => 0.5583, 198 => 0.5647, 199 => 0.5711000000000001, 200 => 0.5775, 201 => 0.584, 202 => 0.5906, 203 => 0.5972, 204 => 0.6038, 205 => 0.6104000000000001, 206 => 0.6172, 207 => 0.6239, 208 => 0.6307, 209 => 0.6375, 210 => 0.6444, 211 => 0.6514, 212 => 0.6583, 213 => 0.6653, 214 => 0.6724, 215 => 0.6795, 216 => 0.6866, 217 => 0.6938, 218 => 0.7010999999999999, 219 => 0.7083, 220 => 0.7156, 221 => 0.723, 222 => 0.7304, 223 => 0.7379, 224 => 0.7454, 225 => 0.7529, 226 => 0.7605, 227 => 0.7681, 228 => 0.7758, 229 => 0.7835, 230 => 0.7912, 231 => 0.7991, 232 => 0.8069, 233 => 0.8148, 234 => 0.8227, 235 => 0.8307, 236 => 0.8387, 237 => 0.8468, 238 => 0.8549, 239 => 0.8631, 240 => 0.8713, 241 => 0.8796, 242 => 0.8879, 243 => 0.8962, 244 => 0.9046, 245 => 0.913, 246 => 0.9215, 247 => 0.9301, 248 => 0.9386, 249 => 0.9473, 250 => 0.9559, 251 => 0.9646, 252 => 0.9734, 253 => 0.9822, 254 => 0.9911, 255 => 1.0]

Function calls and math calculations are costly in terms of processing. Therefore, we've hard-coded all possible transfer values to optimize performance.

Methods

__construct()

Create a new BlurHash instance.

public __construct(["gd"|"imagick" $loader = 'gd' ][, int<1, 9> $componentX = 4 ][, int<1, 9> $componentY = 3 ][, positive-int $maxSize = 64 ]) : mixed
Parameters
$loader : "gd"|"imagick" = 'gd'
$componentX : int<1, 9> = 4
$componentY : int<1, 9> = 3
$maxSize : positive-int = 64
Tags
throws
DriverNotFoundException

decode()

Decode a BlurHash string to an image instance.

public decode(string $blurhash, positive-int $width, positive-int $height) : object
Parameters
$blurhash : string
$width : positive-int
$height : positive-int
Tags
throws
UnableToSetPixelException
throws
UnableToCreateImageException
Return values
object

encode()

Encode an image to BlurHash string.

public encode(UploadedFile|string $data) : string
Parameters
$data : UploadedFile|string
Tags
throws
UnableToGetColorException
Return values
string

normalizeComponent()

Restrict component value between 1 and 9.

public normalizeComponent(int<1, 9> $value) : int<1, 9>
Parameters
$value : int<1, 9>
Return values
int<1, 9>

setComponentX()

Set component x.

public setComponentX(int<1, 9> $componentX) : self
Parameters
$componentX : int<1, 9>
Return values
self

setComponentY()

Set component y.

public setComponentY(int<1, 9> $componentY) : self
Parameters
$componentY : int<1, 9>
Return values
self

setMaxSize()

Set resized image max width.

public setMaxSize(positive-int $maxSize) : self
Parameters
$maxSize : positive-int
Return values
self

decodeAC()

protected decodeAC(int $value, float $max) : array<int, float>
Parameters
$value : int
$max : float
Return values
array<int, float>

encodeAC()

Encode ac factor.

protected encodeAC(array<int, float> $color, float $max) : int
Parameters
$color : array<int, float>
$max : float
Return values
int

pow()

protected pow(float $value, float $exp) : float
Parameters
$value : float
$exp : float
Return values
float

quantise()

protected quantise(float $value) : int
Parameters
$value : float
Return values
int

toRGB()

protected toRGB(int $value) : array<int, float>
Parameters
$value : int
Return values
array<int, float>

toSRGB()

protected toSRGB(float $value) : int<0, 255>
Parameters
$value : float
Return values
int<0, 255>

transform()

Magic transform function.

protected transform(array<int, array<int, array<int, float>>> $colors) : array<int, array<int, float>>

I don't know the meaning of the math calculation.

Parameters
$colors : array<int, array<int, array<int, float>>>
Return values
array<int, array<int, float>>

        
On this page

Search results