williammalone / html5-photoshop-sprite-sheet-creator Goto Github PK
View Code? Open in Web Editor NEWPhotoshop script that creates an HTML animation sprite sheet from Photoshop layers
Home Page: wmalone.com/spritesheet
License: MIT License
Photoshop script that creates an HTML animation sprite sheet from Photoshop layers
Home Page: wmalone.com/spritesheet
License: MIT License
this is testing ๐
When I tell it to start from the bottom, it hides all the layers and stacks them on top of each other. In the video, you'll see me ctrl+z to reveal some of the layers after it was converted
Error 60: Not well-formed (invalid token).
Line: 640
-> <td id="LC1" class="blob-code blob-code-inner js-file-line">/*<span class="pl-c2"></span>Copyright (c) 2014 William Malone (www.williammalone.com)<span class="pl-c2"></span><span class="pl-c2"></span>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:<span class="pl-c2"></span><span class="pl-c2"></span>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<span class="pl-c2"></span><span class="pl-c2"></span>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.<span class="pl-c2"></span>*/<span class="pl-c2"></span><span class="pl-c2"></span>/*<span class="pl-c2"></span><javascriptresource><span class="pl-c2"></span> <name>Create Sprite Sheet from Layers...</name><span class="pl-c2"></span></javascriptresource><span class="pl-c2"></span>*/<span class="pl-c2"></span><span class="pl-c2"></span>var i, prefRulerUnits, prefTypeUnits, frames, frameWidth, frameHeight, mp, dialog, columns, rows,<span class="pl-c2"></span><span class="pl-c2"></span> exit = function () {<span class="pl-c2"></span> <span class="pl-c2"></span> dialog.close();<span class="pl-c2"></span> },<span class="pl-c2"></span><span class="pl-c2"></span> onRowsChanged = function () {<span class="pl-c2"></span> <span class="pl-c2"></span> rows = Number(dialog.msgPnl.rowsGrp.rows.text);<span class="pl-c2"></span> columns = Math.ceil(frames / rows);<span class="pl-c2"></span> dialog.msgPnl.columns.text = 'Columns: ' + columns;<span class="pl-c2"></span> },<span class="pl-c2"></span><span class="pl-c2"></span> createSprite = function () {<span class="pl-c2"></span> <span class="pl-c2"></span> var i, columnIndex, rowIndex;<span class="pl-c2"></span><span class="pl-c2"></span> dialog.hide();<span class="pl-c2"></span> <span class="pl-c2"></span> app.activeDocument.resizeCanvas(columns * frameWidth, rows * frameHeight, AnchorPosition.TOPLEFT);<span class="pl-c2"></span><span class="pl-c2"></span> columnIndex = 0;<span class="pl-c2"></span> rowIndex = 0;<span class="pl-c2"></span> for (i = 0; i < frames; i += 1) {<span class="pl-c2"></span><span class="pl-c2"></span> if (app.activeDocument.layers[i].visible) {<span class="pl-c2"></span> <span class="pl-c2"></span> if (dialog.msgPnl.topDownCheckbox.value) {<span class="pl-c2"></span> activeDocument.layers[i].translate(frameWidth * columnIndex, frameHeight * rowIndex);<span class="pl-c2"></span> } else {<span class="pl-c2"></span> activeDocument.layers[i].translate((frames - 1) * frameWidth - frameWidth * columnIndex, frameHeight * rowIndex);<span class="pl-c2"></span> }<span class="pl-c2"></span> columnIndex += 1;<span class="pl-c2"></span> if (columnIndex >= columns) {<span class="pl-c2"></span> rowIndex += 1;<span class="pl-c2"></span> columnIndex = 0;<span class="pl-c2"></span> }<span class="pl-c2"></span> }<span class="pl-c2"></span> }<span class="pl-c2"></span><span class="pl-c2"></span> app.activeDocument.mergeVisibleLayers();<span class="pl-c2"></span> app.activeDocument.layers[0].name = "Sprite Sheet with " + frames + " Frames";<span class="pl-c2"></span> };<span class="pl-c2"></span><span class="pl-c2"></span>if (app && app.preferences) {<span class="pl-c2"></span> // Save the current preferences<span class="pl-c2"></span> prefRulerUnits = app.preferences.rulerUnits,<span class="pl-c2"></span> prefTypeUnits = app.preferences.typeUnits,<span class="pl-c2"></span> // Change the current preferences to pixel units<span class="pl-c2"></span> app.preferences.typeUnits = TypeUnits.PIXELS;<span class="pl-c2"></span> app.preferences.rulerUnits = Units.PIXELS;<span class="pl-c2"></span>}<span class="pl-c2"></span><span class="pl-c2"></span>try {<span class="pl-c2"></span> if (app && app.activeDocument) {<span class="pl-c2"></span> <span class="pl-c2"></span> // Determine number of visible layers<span class="pl-c2"></span> frames = 0;<span class="pl-c2"></span> for (i = 0; i < app.activeDocument.layers.length; i += 1) {<span class="pl-c2"></span> if (app.activeDocument.layers[i].visible) {<span class="pl-c2"></span> frames += 1;<span class="pl-c2"></span> }<span class="pl-c2"></span> }<span class="pl-c2"></span> <span class="pl-c2"></span> if (frames <= 1) {<span class="pl-c2"></span> alert("Error: Sprite sheet requires more than one visible layer");<span class="pl-c2"></span> } else {<span class="pl-c2"></span> <span class="pl-c2"></span> // Create dialog<span class="pl-c2"></span> dialog = new Window('dialog', 'Sprite Sheet Creator');<span class="pl-c2"></span><span class="pl-c2"></span> dialog.msgPnl = dialog.add('panel', undefined, undefined);<span class="pl-c2"></span> <span class="pl-c2"></span> dialog.msgPnl.frames = dialog.msgPnl.add('StaticText', undefined, 'Number of Frames:');<span class="pl-c2"></span> dialog.msgPnl.frames.alignment = 'left';<span class="pl-c2"></span> dialog.msgPnl.frames.text = "Frames: " + frames;<span class="pl-c2"></span> <span class="pl-c2"></span> columns = frames;<span class="pl-c2"></span> dialog.msgPnl.columns = dialog.msgPnl.add('StaticText', undefined, 'Columns: ' + columns);<span class="pl-c2"></span> dialog.msgPnl.columns.alignment = 'left';<span class="pl-c2"></span> <span class="pl-c2"></span> dialog.msgPnl.rowsGrp = dialog.msgPnl.add('group', undefined, undefined, {<span class="pl-c2"></span> orientation: 'column', <span class="pl-c2"></span> alignChildren: 'left'<span class="pl-c2"></span> });<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.alignment = 'left';<span class="pl-c2"></span> <span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rowsLabel = dialog.msgPnl.rowsGrp.add('StaticText', undefined, 'Rows: ');<span class="pl-c2"></span> <span class="pl-c2"></span> rows = 1;<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rows = dialog.msgPnl.rowsGrp.add('EditText', undefined, rows);<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rows.characters = 3;<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rows.enabled = false;<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rows.addEventListener('changing', onRowsChanged);<span class="pl-c2"></span><span class="pl-c2"></span> dialog.msgPnl.topDownCheckbox = dialog.msgPnl.add('checkbox', undefined, 'First Frame is Top Layer');<span class="pl-c2"></span> dialog.msgPnl.topDownCheckbox.value = true;<span class="pl-c2"></span> dialog.msgPnl.topDownCheckbox.enabled = false;<span class="pl-c2"></span> <span class="pl-c2"></span> dialog.message = dialog.add('StaticText', undefined, 'Initializing...', {<span class="pl-c2"></span> multiline: true<span class="pl-c2"></span> });<span class="pl-c2"></span> dialog.message.text = "";<span class="pl-c2"></span><span class="pl-c2"></span> dialog.btnGrp = dialog.add('group');<span class="pl-c2"></span> dialog.btnGrp.cancelButton = dialog.btnGrp.add('button', undefined, 'Cancel');<span class="pl-c2"></span> dialog.btnGrp.cancelButton.onClick = exit;<span class="pl-c2"></span> dialog.btnGrp.cancelButton.alignment = ['left', 'bottom'];<span class="pl-c2"></span><span class="pl-c2"></span> dialog.btnGrp.createButton = dialog.btnGrp.add('button', undefined, 'Ok');<span class="pl-c2"></span> dialog.btnGrp.createButton.onClick = createSprite;<span class="pl-c2"></span> dialog.btnGrp.cancelButton.alignment = ['right', 'bottom'];<span class="pl-c2"></span> dialog.btnGrp.createButton.enabled = false;<span class="pl-c2"></span><span class="pl-c2"></span> // Determine the frame width based on the active document's dimensions<span class="pl-c2"></span> frameWidth = app.activeDocument.width;<span class="pl-c2"></span> frameHeight = app.activeDocument.height;<span class="pl-c2"></span><span class="pl-c2"></span> // Determine the MP to see if the image is too large to load on iOS devices<span class="pl-c2"></span> mp = frameHeight * frameWidth / 1024 / 1024;<span class="pl-c2"></span> <span class="pl-c2"></span> if (mp * frames > 5) {<span class="pl-c2"></span> dialog.message.text = "Warning: The sprite sheet is too large to be loaded on iOS devices (see http://wmalone.com/maximage for details)";<span class="pl-c2"></span> } else if (mp * frames > 3) {<span class="pl-c2"></span> dialog.message.text = "Warning: The sprite sheet is too large to be loaded on legacy iOS devices (see http://wmalone.com/maximage for details)";<span class="pl-c2"></span> } else {<span class="pl-c2"></span> //dialog.msgPnl.message.text = "Ready to create sprite sheet...";<span class="pl-c2"></span> }<span class="pl-c2"></span> dialog.btnGrp.createButton.enabled = true; <span class="pl-c2"></span> dialog.msgPnl.topDownCheckbox.enabled = true;<span class="pl-c2"></span> dialog.msgPnl.rowsGrp.rows.enabled = true;<span class="pl-c2"></span><span class="pl-c2"></span> dialog.show();<span class="pl-c2"></span> }<span class="pl-c2"></span><span class="pl-c2"></span> } else {<span class="pl-c2"></span> alert("Error: No document open");<span class="pl-c2"></span> }<span class="pl-c2"></span>} catch (ex) {<span class="pl-c2"></span> alert("Error: No document open");<span class="pl-c2"></span>}<span class="pl-c2"></span><span class="pl-c2"></span>if (app && app.preferences) {<span class="pl-c2"></span> // Revert to the previous preferences<span class="pl-c2"></span> app.preferences.typeUnits = prefTypeUnits;<span class="pl-c2"></span> app.preferences.rulerUnits = prefRulerUnits;<span class="pl-c2"></span>}<span class="pl-c2"></span><span class="pl-c2"></span><span class="pl-c2"></span></td>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.