PHP Classes

File: examples/css_code_example.php

Recommend this page to a friend!
  Classes of Arturs Sosins  >  CSS sprite class  >  examples/css_code_example.php  >  Download  
File: examples/css_code_example.php
Role: Example script
Content type: text/plain
Description: CSS code generation example
Class: CSS sprite class
Generate sprite images and CSS to use image styles
Author: By
Last change: credits changed
Date: 5 years ago
Size: 1,958 bytes


Class file image Download
 * This script is developed by Arturs Sosins aka ar2rsawseen,
 * Fee free to distribute and modify code, but keep reference to its creator
 * This class can generate CSS sprite image from multiple provided images
 * Generated image can be outputted to browser, saved to specified location, etc.
 * This class also generates CSS code for sprite image, using element ID's provided with image.
 * It facilitates CSS sprite implementations to existing website structures
 * For more information, examples and online documentation visit:

 * 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
$arr as $error)
//else generate CSS code for added images
$string = $sprite->generate_css("./image_output_example.php");
//outputting CSS code
echo "<style type='text/css'> \n";
"</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;'>