PNG from misc/* in CSS-sprite
Last updated on
30 April 2025
This is an example of the use of the module Imageset.
In the standard delivery drupal folder there are a few misc png-files.
- menu-*.png - used in system.css, you can create a sprite and override the CSS in the manual, but it is not our topic.
Under our task more suitable:
- arrow-*.png - arrows to sort table
- forum-*.png - icons for the standard forum
- watchdog-*.png - icons from watchdog
All pictures in these groups have same size (except the watchdog-error.png, but I think it is fixable) and to display the code they use drupal for the challenge theme('image', .. .) .
For example we will use pictures arrow-asc.png and arrow-desc.png
- Generate one of the free generators sprite image.
- Add it to imageset (mysite/admin/settings/imageset) Name: arrow, Size: 13x13, Full size: 27x27, Offset: 7x7, Orientation: verical
Values of Full size, Offset, Orientation will depend on the chosen method of generating a sprite.
- In your theme in the file template.php (if not, then create a) redefine the output theme('image')
function phptemplate_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) {
$name = '';
switch ($path) {
case 'misc/arrow-asc.png': // for direct sorting
$name = 'arrow:1'; // use imageset 'arrow' index 1
break;
case 'misc/arrow-desc.png': // to reverse sort
$name = 'arrow:2'; // use imageset 'arrow' index 2
break;
}
if ($name) {
$attributes['alt'] = $alt;
$attributes['title'] = $title;
return theme('imageset', $name, NULL, $attributes);
}
else theme_image($path, $alt, $title, $attributes, $getsize);
}
Accordingly, this method is not limited only to a redefinition of the output of standard images.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion