Compiling Functions for QB - chung-leong/qb GitHub Wiki

Functions whose Doc Domments contain the @engine qb tag are automatically compiled for execution through the QB virtual machine the first time it's called. This is true for anonymous functions as well.

Example:

<?php

/**
 * sepia() - give an image a vintage photo look 
 *
 * @engine qb
 * @param image			$image
 * @param float32		$intensity
 *
 * @local float32[4][4]	$YIQMatrix
 * @local float32[4][4]	$inverseYIQ
 * @local float32[4]	$k
 */
function sepia(&$image, $intensity) {
	// convert from RGA to YIQ color space
	$YIQMatrix = array(
		array(0.299,  0.596,  0.212, 0.000),
		array(0.587, -0.275, -0.523, 0.000),
		array(0.114, -0.321,  0.311, 0.000),
		array(0.000,  0.000,  0.000, 1.000),
	);
	$image = mv_mult($YIQMatrix, $image);
	
	// clear I and Q
	$k = array(1, 0, 0, 1);
	$image *= $k;		
	
	// set I to intensity
	$k = array(0, $intensity, 0, 0);
	$image += $k;
	
	// convert pixels back to RGA color space
	$inverseYIQ = array(
		array(1.0,    1.0,    1.0,    0.0),
		array(0.956, -0.272, -1.10,   0.0),
		array(0.621, -0.647,  1.70,   0.0),
		array(0.0,    0.0,    0.0,    1.0),
	);	
	$image = mv_mult($inverseYIQ, $image);
}

$image = imagecreatefrompng("images/malgorzata_socha.png");

sepia($image, 0.2);

header("Content-type: image/jpeg");
imagejpeg($image);

?>