sissonb
sissonb

Reputation: 3780

SCSS - Getting Image Dimensions

I am using the inline-image function to create icon classes. This is my current SCSS:

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: 30px;
    width: 41px;
}

I am looking for a function that can determine the width and height of the image so I can do something like this:

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: image-height("icons/home/folder.png", 'image/png');
    width: image-width("icons/home/folder.png", 'image/png');
}

Does anything like this exist?

Upvotes: 7

Views: 17611

Answers (1)

welldan97
welldan97

Reputation: 3076

Found this http://compass-style.org/reference/compass/helpers/image-dimensions/

You've guessed the right function names.

To use them you'll need to install compass.

It will be something like this:

@import "compass/helpers";

.folder {
    background: inline-image("icons/home/folder.png", 'image/png') no-repeat center;
    height: image-height("icons/home/folder.png");
    width: image-width("icons/home/folder.png");
}

By the way I would recommend you to use sprites for icons: http://compass-style.org/reference/compass/helpers/sprites/

Upvotes: 10

Related Questions