Image - chung-leong/qb GitHub Wiki
When you pass a GD image to a PHP+QB function, QB will convert the pixels to the format indicated by the parameter's type declaration. Color values can be represented by floating point numbers or integers. While using a floating point representation increases memory requirement fourfold, the ease of manipulation it offers generally makes it worthwhile.
Floating Point Representations
The following type declarations are possible:
float32[][][4]
This is the most common format. Each pixel is a four-element array of 32-bit floating point numbers, each of which represents one of the four channels: red, green, blue, and alpha. The value of each channel varies between 0 and 1. A white pixel that is fully opaque is [1, 1, 1, 1], while a black pixel that is half transparent is [0, 0, 0, 0.5]. When changes are copied back into the original GD image upon return, QB will clamp all values to within the acceptable range: negative values become 0, while values greater than 1 become 1.
Two initial dimensions are left undefined to accommodate incoming images of various sizes. The first dimension are the scanlines of the image. The expression count($image)
therefore yields the height of the image. The second dimension are the pixels in a given scanline. The expresion count($image[0])
yields the width of the image.
The intrinsic function sample_bilinear and sample_nearest can be used to obtain color values from non-integer, "off-the-grid" coordinates.
The shorthand image4 or image can be used to specify this format.
float32[][][3]
Like float32[][][4] but with the alpha channel omitted.
The shorthand image3 can be used to specify this format.
float32[][][2]
A monochrome image with alpha. The first channel is luminance, calculated from the RGB values using the following formula:
L = R * 0.299 * + G * 0.587 + B * 0.114
The shorthand image2 can be used to specify this format.
float32[][][1]
A monochrome image. The sole channel is luminance.
The shorthand image1 can be used to specify this format.
float32[][4]
Similar to float32[][][4], except the pixels are stored in a single linear array, making it possible to scan through all of them in a single foreach() loop.
The absence of the image's width and height means the sampling functions cannot be used.
float32[][3]
Analogous to float32[][4], with three channels.
float32[][2]
Analogous to float32[][4], with two channels.
float32[][1]
Analogous to float32[][4], with a single luminance channel.
float64[][][4]
64-bit version of float32[][][4]. The higher precision offers by double-precision floating point will generally not lead to any perceptible difference in the output image.
float64[][][3]
64-bit version of float32[][][3].
float64[][][2]
64-bit version of float32[][][2].
float64[][][1]
64-bit version of float32[][][1].
float64[][4]
64-bit version of float32[][4].
float64[][3]
64-bit version of float32[][3].
float64[][2]
64-bit version of float32[][2].
float64[][1]
64-bit version of float32[][1].
Integer Representations
uint8[][][4]
Each pixel is a four-element array of 8-bit unsigned integers, each of which represents ones of the four channels: red, green, blue, and opacity. Red, green, and blue vary between 0 and 255. Opacity varies between 0 and 127, with 0 meaning fully transparent and 127 meaning fully opaque.
The sampling functions do not support this or any of the integer formats.
uint8[][4]
Similar to uint8[][][4], except the pixels are stored in a single linear array.
uint32[][]
Each pixel is a 32-bit unsigned integer. Essentially the same as uint8[][4], but with the bytes packed into a 32-bit integer.
uint32[]
Similar to uint32[][], except the pixels are stored in a single linear array.