An easy way to generate retina ready sprites
This Compass extension will allow you to create retina ready sprites from scratch. Just drop your images on the right folders, type some Compass mumble jumble and you are ready to go!
gem installl compass-retinator
Now do a require in your Compass config.rb
require 'compass-retinator'
First thing to do is drop your images on the right folders. In this case I have set two folders icons and icons-sprites inside my image folder.
Next, we need to tell Compass where those image are. Add this line to variables.saas or somewhere else
$sprites: sprite-map("icons/*.png")
$sprites_retina: sprite-map("icons-sprites/*.png")
Now we need to init awesomeness, add this line to your project:
@import "compass_retinator"
You can pass several parameters to obtain the right result, some valid options are:
// This will import plain.png
.plain
+sprite(plain)
// This will import boat.png, boat_hover.png and boat_active.png
.boat
+sprite(boat, $hover_state: true, $active_state: true)
// This will import console.png plus 40px of padding on the sides
.console
+sprite(console, $spacing: 40px)
// This will import people.png and it will not set any dimension on this elemments
.people
+sprite(people, $dimensions: False)
Please be sure that your icons scale proportionally. If the non-retina icons are 16x16 your retina icons must be 32x32 and not 30x32 and definitely not 45x34
You're probably running a rails app. This is a weird issue with compass-rails. For some reason compass-rails does not create the sprites on demand and doesn't understand the sprite-map
.
One workaround is to tell Compass to re-declare your sprites assets, so add this line at the top of your variables:
@import "icons/*.png"
@import "icons-sprites/*.png"
Unfortunately Compass doesn't support extra options with this layout. Try to use the default layout or the horizontal layout.
Please, keep in mind, if you are adding extra padding around the sprite item, you will also need to tell Compass to add some extra space on every sprite item. Just past the varible $spacing: XXpx
$sprites: sprite-map("icons/*.png", $spacing: 10px)
$sprites_retina: sprite-map("icons-sprites/*.png", $spacing: 20px)
Copyright (c) 2013 Restorando
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.