Skip to content

Importing Pixel Bender Kernels

chung-leong edited this page Mar 29, 2013 · 6 revisions

The @import tag directs QB to import a Pixel Bender kernel into a function:

<?php
/**
 * @engine qb
 * @import pbj/sepia.pbj
 *
 * @param image	$dst
 * @param image	$src
 * @param float32 $intensity
 */
function sepia_filter(&$dst, $src, $intensity) {
}

qb_compile();

?>

In the example above, the instructions contained in sepia.pbj are imported into the function sepia_filter(). Afterward, this function can be used elsewhere to apply the sepia effect on an image:

<?php

$image = imagecreatefrompng("images/malgorzata_socha.png");
$output = imagecreatetruecolor(imagesx($image), imagesy($image));

sepia_filter($output, $image, 0.2);

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

?>

You can use qb_extract() to obtain the function declaration for a given PBJ file:

<?php

echo qb_extract("pbj/sepia.pbj", QB_PBJ_DECLARATION);

?>

The example code above will produce the following:

/**
 * Sepia()	a variable sepia filter (Adobe Systems)
 *
 * @engine	qb
 * @import	pbj/sepia.pbj
 *
 * @param	image	$dst
 * @param	image	$src
 * @param	float32	$intensity
 *
 * @return	void
 */
function Sepia(&$dst, $src, $intensity) {}
Clone this wiki locally