Skip to content


return sprite sheet width #1076

brewster1134 opened this Issue · 6 comments

4 participants


how can i get the width/height of the compiled sprite sheet? the only solution i have found is looping through all the sprites and finding the largest one using image-width(sprite-file($map, $sprite).

Is there a way to get the sprite sheet url to use with image-width?

Compass member

This should be easy to add. If i may ask whats the use case?


It is for implementing a spriting solution for retina images. I know there is a lot of various techniques being used until this gets rolled into compass, but cutting the background-size width in half is neccessary when leveraging compass' current spriting strategy.


This will work:

$sprite-map-width: image-width( sprite-path($map) );

If you're having trouble using the above, use @debug( sprite-path($map) ) to find out if the file path is being set correctly, in my scenario I had set the generated_images_dir in my config.rb which the sprite-path function does not respect, so I needed to create a separate function to relink the result of sprite-path($map) to my actual folder like so:

/** Returns the correct image path of the generated_images_dir. */
@function sprt($path) {
  @return '../images/sprites/#{$path}';

$sprite-map-width: image-width( sprt( sprite-path($map) ) );

I agree however that it would be nice if there was a direct helper for this, something like: sprite-map-width($map) to give you the width of the map for example.


@jannisg That is working great. thanks.

@scottdavis scottdavis closed this in f8d9cc8

can these helpers (sprite-width, sprite-height ) be used within compass 0.12.2? It doesn't work for me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.