Location: PHPKode > scripts > CSS sprite class > examples/css_code_example.php

 * This example shows how to generate css code and use it with created CSS sprite
//declaring class instance
$sprite = new spritify();

//adding test images
$sprite->add_image("../test_images/php.jpg", "jpeg");
$sprite->add_image("../test_images/php.gif", "gif");
$sprite->add_image("../test_images/elephpant.png", "elephant");

//retrieving error
$arr = $sprite->get_errors();
//if there are any then output them
	foreach($arr as $error)
		echo "<p>".$error."</p>";
	//else generate CSS code for added images
	$string = $sprite->generate_css("./image_output_example.php");
	//outputting CSS code
	echo "<style type='text/css'> \n";
	echo $string;
	echo "</style> \n";
<!-- HTML elements that use CSS sprites for background using generated CSS code -->
<div id='jpeg' style=' border:1px solid green;'>
<div id='gif' style='float: right;background-color: green; border:1px solid red;'>
<div id='elephant' style='background-color: red; border:1px solid green;'>
Return current item: CSS sprite class