sabi/spritesheet-generator

There is no license information available for the latest version (dev-main) of this package.

Simple php library that combine seperated images(png) to one spritesheet image and replace background color with transparent and generate css

dev-main 2023-06-05 06:10 UTC

This package is auto-updated.

Last update: 2025-05-05 10:11:30 UTC


README

Simple php library that combine seperated images(png) to one spritesheet image and replace background color with transparent and generate css

Installation

Install with composer

  composer require sabi/spritesheet-generator

Tech Stack

Server: PHP

Methods

__constructor

  SpritesheetGenerator(tileWidth, tileHeight)
Parameter Type Description
tileWidth integer Required.
tileHeight integer Required.

add images paths

  ->addImagesPaths(imagesPaths)
Parameter Type Description
imagesPaths array Required.

save generated spritesheet image

  ->saveSpritesheetTo(srcSpritesheetPath)
Parameter Type Description
srcSpritesheetPath string Optional. default is './sprite-sheet.png'

save css stylesheet

  ->saveStyleSheetTo(srcStylesheetPath, cssClassPrefix)
Parameter Type Description
srcStylesheetPath string Optional. default is './sprite-styles.css'
cssClassPrefix string Optional. default is 'sh-icon'

generate images sprite sheet and css stylesheet

  ->generateSheet()

Usage/Examples

<?php

require '../vendor/autoload.php';

use Saber\SpritesheetGenerator\SpritesheetGenerator;

$sg = new SpritesheetGenerator(48,48);
$sg->addImagesPaths([
    __DIR__.'/imgs/1.png',
    __DIR__.'/imgs/2.png',
    __DIR__.'/imgs/3.png',
    __DIR__.'/imgs/4.png'
])
->generateSheet()
->saveSpritesheetTo('./menu-icons.png')
->saveStyleSheetTo('./menu-icons.css');