Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Generate CSS sprites and thumbnail images on the fly in ASP.NET sites

, 9 Jun 2012
Reduces page load times of ASP.NET web sites by combining page images and CSS background images into CSS sprites. Compresses and physically resizes images to make thumbnails. Caters for repeating background images.
CssSpriteGenerator.zip
Code
CssSpriteGenerator.suo
CssSpriteGenerator.vssscc
CssSpriteGenerator
bin
Debug
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
Release
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
ConfigElements
DTOs
Enums
External
SimplePaletteQuantizer
Extensions
Helpers
Quantizers
HSB
Median
Octree
Popularity
Uniform
GeneratorNs
ImageReferences
Mapper
obj
Debug
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties.Resources.Designer.cs.dll
Release
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
Utils
DemoSite_AutoResized
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
largeimages
vanuatu1.JPG
DemoSite_CombineAndMinify
___generated
Bin
CombineAndMinify.dll
CombineAndMinify.pdb
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
EcmaScript.NET.modified.dll
Yahoo.Yui.Compressor.dll
DemoSite_CompressedJpeg
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
largeimages
vanuatu1.JPG
vanuatu2.JPG
DemoSite_CompressedPng
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
cart.png
contactus.png
print.png
DemoSite_CssBackgroundImages
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
css
images
button-green-left.png
button-green-right.png
button-green-w100.png
button-orange-left.png
button-orange-right.png
button-orange-w100.png
gradient-hor-blue-w20h1.png
gradient-hor-green-w20h1.png
gradient-vert-blue-w1h20.png
gradient-vert-green-w1h20.png
gradient-vert-lightblue-w1h10.png
gradient-vert-orange-w1h10.png
DemoSite_Database
App_Browsers
PageAdapter.browser
App_Code
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
cart.png
contactus.png
print.png
DemoSite_DefaultConfig
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
band-4bits.png
cart.png
circles-8bits.gif
contactus.png
dragonboats-thumbnail1.jpg
dragonboats-thumbnail2.jpg
dragonboats-thumbnail3.jpg
print.png
rectangles-4bits.png
smallrectangles-4bits.png
DemoSite_FolderImages
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
cart.png
contactus.png
print.png
DemoSite_Gallery
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
cart.png
contactus.png
print.png
largeimages
vanuatu1.JPG
vanuatu2.JPG
DemoSite_QuickStart
App_Browsers
PageAdapter.browser
Bin
CssSpriteGenerator.dll
CssSpriteGenerator.pdb
images
200x200.png
90x90.gif
90x90.jpg
90x90.png
photos
vanuatu2.JPG
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mapper
{
    /// <summary>
    /// A canvas is a rectangle of a given size that lets you add smaller rectangle.
    /// The canvas will place each rectangle so that it doesn't overlap with any other rectangle that is already 
    /// on the canvas.
    /// </summary>
    public interface ICanvas
    {
        /// <summary>
        /// Value denoting an unlimited width or height. You would pass this in to SetCanvasDimensions.
        /// </summary>
        int UnlimitedSize { get; }

        /// <summary>
        /// Sets the dimensions of the canvas.
        /// If there were already rectangles on the canvas when this is called, those rectangles will be removed.
        /// 
        /// Be sure to call this method before you call AddRectangle for the first time.
        /// </summary>
        /// <param name="canvasWidth">New width of the canvas</param>
        /// <param name="canvasHeight">New height of the canvas</param>
        void SetCanvasDimensions(int canvasWidth, int canvasHeight);

        /// <summary>
        /// Adds a rectangle
        /// </summary>
        /// <param name="rectangleWidth">Width of the rectangle</param>
        /// <param name="rectangleHeight">Height of the rectangle</param>
        /// <param name="rectangleXOffset">X position where rectangle has been placed</param>
        /// <param name="rectangleYOffset">Y position where rectangle has been placed</param>
        /// <param name="lowestFreeHeightDeficit">
        /// Lowest free height deficit for all the rectangles placed since the last call to SetCanvasDimensions.
        /// 
        /// This will be set to Int32.MaxValue if there was never any free height deficit.
        /// </param>
        /// <returns>
        /// true: rectangle placed
        /// false: rectangle not placed because there was no room
        /// </returns>
        bool AddRectangle(
            int rectangleWidth, int rectangleHeight, out int rectangleXOffset, out int rectangleYOffset,
            out int lowestFreeHeightDeficit);

        /// <summary>
        /// The canvas keeps statistics, on for example the number of times a FreeAreas is generated.
        /// Use this method to fill an object that implements ICanvasStats with these statistics.
        /// 
        /// Note that calling SetCanvasDimensions resets all counters.
        /// </summary>
        /// <param name="canvasStats">
        /// Reference to object to be filled.
        /// 
        /// If this is null, nothing happens (so there is no exception).
        /// </param>
        void GetStatistics(ICanvasStats canvasStats);


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Matt Perdeck
Web Developer
Australia Australia
Twitter: @MattPerdeck
Blog: mattperdeck.com
Current project: JSNLog JavaScript Logging Package
 
Matt has over 6 years .NET and SQL Server development experience. Before getting into .Net, he worked on a number of systems, ranging from the largest ATM network in The Netherlands to embedded software in advanced Wide Area Networks and the largest ticketing web site in Australia. He has lived and worked in Australia, The Netherlands, Slovakia and Thailand.
 
He recently wrote a book, ASP.NET Performance Secrets (www.packtpub.com/asp-net-site-performance-secrets/book) in which he shows in clear and practical terms how to quickly find the biggest bottlenecks holding back the performance of your web site, and how to then remove those bottlenecks. The book deals with all environments affecting a web site - the web server, the database server and the browser.
 
Matt currently lives in Sydney, Australia. After 2 years at Readify, he now works at the global professional services company PwC. His current contract ends at 29 June 2014.
Follow on   Twitter   Google+

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 10 Jun 2012
Article Copyright 2011 by Matt Perdeck
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid