127

Are there any good tools to make css sprites?

IDEALLY I'd want to give it a directory of images and an existing .css file that refers to those images and have it create a big image optimized with all the little images AND change my .css file to refer to those images.

At the least I'd want it to take a directory of images and generate a big sprite and the .css necessary to use each as a background.

Are there any good photoshop plugins or fully blown apps to do this?

Rick Viscomi
  • 8,180
  • 4
  • 35
  • 50
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • See also http://stackoverflow.com/questions/519774/searching-for-a-direct-way-to-load-a-slice-of-a-gif-png-jpg-into-an-html – tehvan Feb 09 '09 at 07:29
  • Could you please elaborate a little more, are you trying to compile all the sprites on one larger image and then use css to display the part of the image that contains the right sprite. (sliding doors technique) – teh_noob Feb 09 '09 at 07:30
  • check also this: http://spritepad.wearekiss.com/ ;) – patrick Mar 29 '12 at 09:04
  • 1
    is there a way to change the background color so I can see my white icons on spritepad? – Jim Aug 10 '12 at 20:26
  • I wrote an example for you, just format the printf for your css (different people use different methods, so I just used an output that is easily parseble - feel free to change it) http://stackoverflow.com/a/13281578/1162141 – technosaurus Nov 09 '12 at 15:54
  • Partick, shouldnt your comment be an independent answer? – iankit Jan 17 '13 at 10:02
  • 24
    I really don't understand why this was closed?? There seems to be lots of good useful answers. This arguably should be a Superuser question because I don't mention any particular programming language but I like the answers I got and they've obviously been useful to many. – Simon_Weaver Feb 21 '13 at 19:57
  • 3
    Please god do not delete this question, it is the most helpful list on the internet for this problem, and is certainly related to programming *(even if it's not a programming question per-say)*. This is definitely a judgement-call, and should **not** have been force-closed by the mods; that is what the community vote-closing system is for.... – BlueRaja - Danny Pflughoeft May 22 '13 at 21:16
  • I'm a big fan of glue. http://glue.readthedocs.org/en/latest/ It works on Windows, OSX, and Ubuntu/Debian. – TryHarder Jan 20 '14 at 11:38
  • adobe fireworks, although deprecated is a good piece of software for making sprites. no complaints. – pgee70 Nov 05 '16 at 02:07

21 Answers21

50

Instant Sprite is an in-browser CSS sprite generator I'm working on. It's really fast, but doesn't have quite as many features as some of the others. It currently only works in Firefox or Chrome, since it uses JavaScript FileReader and HTML Canvas to generate the sprites inside the web browser without uploads.

Brian Grinstead
  • 3,480
  • 5
  • 29
  • 23
  • 1
    Wow, what a great tool. Thanks! – Vivian River Nov 17 '11 at 15:07
  • I've used your tool to work on some production web sites since you've posted here. It's very simple and easy. – Vivian River Jun 26 '12 at 15:29
  • Daniel, great to hear that you have been using it!! I use it all the time, and I'm glad that others are get some benefit from it too. – Brian Grinstead Jun 27 '12 at 15:02
  • 7
    +1. Your tool is far better than the rest I've tried. – Ed Bayiates Aug 08 '12 at 22:10
  • 3
    this is the most intuitive one yet... thanks... (although, it should include the "smart" layout of sprites to minimize performance issues) – kumarharsh Aug 09 '12 at 20:02
  • 2
    Thanks everyone! @Harsh, I agree about the layout - I started experimenting with that quite a while ago but never quite got it working: https://github.com/bgrins/InstantSprite/tree/bin-pack – Brian Grinstead Aug 17 '12 at 15:45
  • THIS IS THE BEST SPRITE TOOL I've used! – Damon Aw Oct 16 '12 at 14:35
  • Thank you very much for this tool. This was just pleasant to use. – Seong Lee May 18 '14 at 09:28
  • Great job. Some feedback: 1) In the output CSS, replace `0px` with `0` to save a few chars. 2) If most input images have the same size, move those dimensions into the top-level CSS rule and only override as needed (I have three from 250 which are slightly different). 3) Remove the extra whitespace before the closing `}` brace. 4) Did I mention this is a great site? – Drew Noakes Oct 07 '14 at 16:39
  • @DrewNoakes Thanks for the feedback :). I haven't been doing a lot of work on it lately but it is all open source: https://github.com/bgrins/InstantSprite so if anyone wants to help out with some of these it'd be awesome. I think 1 and 3 would be pretty easy fixes. As for 2: Dimensions are defined globally here: https://github.com/bgrins/InstantSprite/blob/1ced360acbd312557c8849b465e580b2d6c0a1f5/site/scripts/instantsprite.js#L253. I think it'd be possible to change this to instead see if > 50% or 75% of them use the same dimension to predefine as you suggest and override others. – Brian Grinstead Oct 29 '14 at 19:54
  • @BrianGrinstead, just submitted a [pull request](https://github.com/bgrins/InstantSprite/pull/9) that covers these features. Ended up deciding that the test for reusing dimensions should just assess whether more than one images shares a size. Tested locally and all seems well. – Drew Noakes Oct 30 '14 at 10:29
48

This will do 90% of the work for you: CSS Sprite Generator. You'll still need to edit the rules yourself, but the tool will give you the code fragments you need for the new CSS file.

Edgar
  • 6,022
  • 8
  • 33
  • 66
Sophie Alpert
  • 139,698
  • 36
  • 220
  • 238
31

There is now Sprite Me by Steve Souders. Just tries it out and it seems to work pretty well.

Here is the link http://spriteme.org/ and here is the blog post announcing it.

http://www.stevesouders.com/blog/2009/09/14/spriteme/

Jauder Ho
  • 1,345
  • 1
  • 16
  • 22
  • 2
    +1 This is amazingly easy to use: Just navigate to the page you want and click the SpriteMe bookmarklet... It creates the images and CSS automatically! – Chuck Le Butt Oct 15 '10 at 11:35
  • It's a nice tool, but, it requires a ZIP file of your images and the order it puts your sprites in is the ZIP order. Brian's tool below allows you to upload files and drag&drop to change order. – Ed Bayiates Aug 08 '12 at 22:11
  • I like that it has source code freely available – lkraav Aug 24 '13 at 03:12
13

This looks promising :

http://csssprites.org/

Also i found this article which has some useful information, and even some reader comments worth reading.

Also apparently google web toolkit has something - so if you're using that it might be worth checking out.

ripper234
  • 222,824
  • 274
  • 634
  • 905
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • Seems like the page doesn't work anymore... – Bob Sep 12 '11 at 18:25
  • http://smartsprites.osinski.name/ was renamed http://csssprites.org/, so I edited it for you. It seems to be the one of the few options that can be integrated into the build process, from what I've seen here. – ripper234 Oct 30 '11 at 13:23
9

Try this:

http://spritepad.wearekiss.com/

Ivin
  • 4,435
  • 8
  • 46
  • 65
  • This is definitely legitimate. Saved spritemaps IMHO are a key, so only relevant images and lines of code would have to change over time, instead of recalculating the whole coordinate set with every image content change. – lkraav Aug 24 '13 at 03:30
7

ZeroSprites is a CSS sprites generator aimed at area minimization using VLSI floorplaning algorithms.

clyfish
  • 10,240
  • 2
  • 31
  • 23
6

found this one pretty fast tho that 500K upload limit might be a pain. source code is available here

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
  • why would 500kb upload be a pain? i'd probably never want to upload > 100kb – Simon_Weaver Feb 09 '09 at 09:06
  • I said it 'might' be a pain. It sorta depends on the application no ? .. A zip file full of medium size PNGs, for example, on a sizable grid ~ ~could~ run close to this number. if its all little bitmaps then sure/ no prob. – Scott Evernden Feb 09 '09 at 14:41
  • 1
    ya but the whole point of css sprites is to prevent lots of little images being loaded with many requests. if you really did have that many little sprites it would take a long time to load in which time none would be displayed. best to keep them i'd think at most 100kb. you can always do several – Simon_Weaver Feb 10 '09 at 00:14
  • i do a lot of work with images. maybe not little css bitmaps. so maybe that's why i gave the caveat. your needs are different/ ok. 500kb will arrive in a second on most broadbands. i was first to supply the accepted answer to your query and here i am down~voted and defending my language? whatever... – Scott Evernden Feb 10 '09 at 05:13
  • It was a pain for me, since the images that I started with ended up being a bundle greater in size than that limit, so I had to cut out or optimize before I could even use it. – Kzqai Jan 01 '11 at 03:28
4

Just use http://sprites.scherpontwikkeling.nl/ it can generate sprites from website URL's as well...you can integrate your sprites after developing your website. It's very easy to use ;)

John
  • 41
  • 1
4

Tonttu is Adobe AIR based application which provides easy interface for creating powerful CSS Sprites images. You can specify FiledWidth and FieldHeight or sort images.
Create CSS Sprites Images with Tonttu Desktop Tool

Dudu
  • 1,184
  • 1
  • 10
  • 26
4

Not clear yet if it'll make it into the core ASP.NET framework but here's a Microsoft codeplex project for csssprites :

http://aspnet.codeplex.com/releases/view/50869

if you like it - use it - or just like the idea then add a comment. I think this would be a great thing to have in the ASP.NET framework. Have not personally used it (I had to invent the wheel myself) but its got good reviews.


It includes the following components:

  • API for automatically generating sprites and inline images
  • Controls and helpers which provide a convenient way of calling into the API

Features Added in Second Release:

  • A CSS linking control for Web Forms (selects the proper CSS file for the user's browser, but does not display an image)
  • Using custom folder paths other than App_Sprites
  • Changing the tiling direction of sprite images
  • Merging the generated CSS with a user's own CSS

Features under consideration for future releases:

  • Automatically selecting the most efficient sprite background colour
  • Automatically minifying the rendered CSS
  • Compiling against .NET 3.5
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
3

Not a direct answer but to my fellow developers and web integrators, consider simply aligning each sprite to powers of two; eg a 16 pixel or 32 pixel grid. It makes calculating offsets in the CSS file much easier. All the white space between does not matter as the gifd and png formats compress that very well.

  • good tip, although i'm mainly trying to combine text headers (1-2kb each) into a single file. i'm not worried too much about white space because i know it'll get compressed out - i just dont completely understand why tools to make sprites make so much of it – Simon_Weaver Feb 13 '09 at 00:46
  • One caveat to this - while the whitespace in the image will be compressed for transport, it is expanded and occupies memory when loaded the browser. Blind use of automatic sprite generation tools can lead to some huge images, which can spike memory use on those pages. Some care is needed in grouping images to form sprite sheets to keep this within reasonable bounds. – Sam Foster Jun 21 '10 at 10:38
  • Sam: True! Found this out later. If the sprite image is very wide or tall that's something to consider! Especially for mobile phone apps (less memory). Simon: the white space is probably because of limitations of CSS. Even when you use no-repeat on a background, the sprite image will show through padding, line-height and basically all the element's background area except margins and borders. Say for example you have an icon for a link. If the link would span mutliple lines then other icons of the sprite might show through. Adding enough whitespace makes this more "resilient". –  Jul 11 '10 at 21:56
  • @Simon_Weaver - Based on everyones feedback here, I posted a sprite tool that is simple http://stackoverflow.com/a/13281578/1162141 – technosaurus Nov 09 '12 at 14:03
3

Compass CSS Framework has automatic sprite generation.

Samuel Katz
  • 24,066
  • 8
  • 71
  • 57
  • 2
    I'm stunned by the amount of people not using Compass for Sprite Generation. Compass was born for this... – pyronaur May 27 '13 at 10:15
2

Here is a script that combines images via a Photoshop script into CSS sprites. It won't do a sprite map as you asked, but it will combine images in multiples of two (2, 4, 8) if they are the same size. I prefer combining similar images (normal, hover, selected, parent of selected) than having all the images in one file.

2

if you are using ruby on rails, there is an easy to install library to generate css sprites.

http://github.com/aberant/spittle

aberant
  • 41
  • 2
2

There is a new tool out there called ActiveSprites, part of the active_assets gem.

Github: http://bitly.com/eRTwU4

You use a ruby dsl to define your sprites and then do "rake sprites" and the sprites and corresponding stylesheets get generated.

It's rad!

Here's some sample code,

# config/sprites.rb
Rails.application.sprites do
  sprite 'sprites/sprite1.png' => 'sprites/sprite1.css' do
    _'sprite_images/sprite1/1.png' => 'a.one'
    _'sprite_images/sprite1/2.png' => 'span.two'
  end
end
shwoodard
  • 429
  • 4
  • 5
2

If you like Java, then you can use GWT 1.5+ which comes with something called "ImageBundle." The GWT compiler will handle all the nasty details for you. You won't even have to code a single line of JavaScript or write any CSS.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
2

https://github.com/northpoint/SpeedySprite

This tool takes a novel approach in that it assembles your requested images on the fly as an http service. This makes the whole process pretty simple (no preprocessing required, change images any time): You start the service and then reference whatever images you want in your HTML:

<link href="css/my-images-dir/" rel="stylesheet">
<div class="my-image-name-here" />

Because it's dynamic, you can even make sprites from a dynamic set of images such as a thumbnail page. Doesn't support JPEG though, but PNG and GIF works fine.

Magnus
  • 10,736
  • 5
  • 44
  • 57
1

None of these tools met my requirements, so I wrote one that uses Mark Tylers's tiny image library, mtpixel (now part of mtcelledit) It isn't super extensive but it is easily extensible through mtpixel's built in functions that include: grayscale, color inversion, rotation, sharpen, quantize, posterize, flip (vertical and horizontal), transform, rgb->indexed, indexed->rgb, edge detect, emboss, drawing polygons, text and more.

All you do is pass it a set of images as args (supports png, gif and jpeg) and it will output an rgb png called sprite.png along with the useful image slicing data to stdout. I use it in bash scripts to spritify an entire directory of images and output the slicing data for automatic generation of css (with the hope of eventually making it capable of replacing existing img tags automagically with a bit of creative sed/awk)

Binary packages for puppy linux will be here:

http://murga-linux.com/puppy/viewtopic.php?t=82009

My use case only required splicing the images vertically into a new png, so that is all it does, but my source code is public domain and the mtcelledit library is gpl3. With mtpixel statically linked, the binary is <100kb (only a few kb when dynamically linked) and the only other dependencies are libpng, libjpeg and libgif (and freetype with the official mtpixel, but I didn't need the text support, so I commented out the freetype bits in the static build)

feel free to modify for your own needs:

#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <mtpixel.h> 

int main( int argc, char *argv[] ){ 
int i=0,height=0,width=0,y=0; 
mtpixel_init(); 
mtImage *imglist[argc]; 
argc--; 
do{   imglist[i] = mtpixel_image_load( argv[i+1] ); 
   height+=imglist[i]->height; 
   if (imglist[i]->width > width) width=imglist[i]->width; 
} while (++i < argc); 
imglist[argc]=mtpixel_image_new_rgb(width,height); 
imglist[argc]->palette.trans=0; 
i=0; 
do{   if (imglist[i]->type == MTPIXEL_IMAGE_INDEXED) 
      mtpixel_image_paste(imglist[argc],mtpixel_image_to_rgb(imglist[i]),mtpixel_brush_new(),0 ,y); 
   else mtpixel_image_paste(imglist[argc],imglist[i],mtpixel_brush_new(),0 ,y); 
   printf("name=%s;width=%d;height=%d;y_offset=%d\n",argv[i+1],imglist[i]->height,imglist[i]->width,y); 
   y+=imglist[i]->height; 
   mtpixel_image_destroy( imglist[i] ); 
}while (++i < argc); 
   mtpixel_image_save( imglist[argc], "sprite.png", MTPIXEL_FILE_TYPE_PNG, 5 ); 
mtpixel_quit(); 
return 0; 
}
technosaurus
  • 7,676
  • 1
  • 30
  • 52
1

I suggest you to use Sprite Master Web. I generates sprite sheets automatically and exports CSS code for you. It always tries to generate smallest sprite sheets with advanced algorithms.

Here is a screenshot and youtube video

enter image description here

bateristt
  • 176
  • 15
0

If you are using .net, check out http://www.RequestReduce.com. It not only creates the sprite file automatically, but it does it on the fly through an HttpModule along with merging and minifying all CSS. It lso optimizes the sprite image using quantization and lossless compression and it handles the serving of the generated files using ETags and Expires headers to ensure optimal browser caching. The setup is trivial involving just a simple web.config change. See my blog post about its adoption by the Microsoft Visual Studio and MSDN Samples gallery.

Matt Wrock
  • 6,590
  • 29
  • 23
0

i recently find this tools : SpriteRight http://spriterightapp.com/

SpriteRight is a CSS spritesheet generator for the Mac that lets you import your existing images or stylesheets. Make your sites load faster, cut bandwidth costs and save time. SpriteRight even generates CSS code on the fly.

prestarocket
  • 733
  • 3
  • 12
  • 30
  • Worth noting, this is not a free or open source app but fairly priced at $4.99. It's well built and does good PNG compression, more functionality than the above "Sprite Master Web". – t.mikael.d Feb 20 '12 at 11:06
  • And it's mac only aswell. – Mahn Jan 22 '13 at 16:07