Skip to content

Instantly share code, notes, and snippets.

@loadedsith
Created May 30, 2014 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loadedsith/3ae08f75d5d406d571cf to your computer and use it in GitHub Desktop.
Save loadedsith/3ae08f75d5d406d571cf to your computer and use it in GitHub Desktop.
Photoshop to spritesheet scripts (JS and SCSS)
//You have to run the script from the ExtendScript tool (Applications/Utilities/Adobe Utilities-CS6/ExtendScript Toolkit CS6/ExtendScript Toolkit.app)
/*JS*/
var counts = app.activeDocument.countItems;
var NumberOfCounts = counts.length;
var count = 0;
$.write("[");
while(count < NumberOfCounts ){
var newPos ={};
$.write("(-" + counts[count].position[0] + ', -' + counts[count].position[1] + "),");
count++;
}
$.writeln("]");
/*
SCSS:
.sprite{
margin:0;
display: block;
background-repeat:no-repeat;
border:1px solid black;
}
.spriteLabel {
margin-top: -1.5em;
display:block;
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33b
$classes: 'sprite1', 'sprite2', [etc];
$positions:((-15.5px -4.5px)(-0.5px -262.5px)(-0.5px -334.5px)(-52.5px -273.5px)(-150.5px -272.5px)(-253.5px -266.5px)(-319px -160px)(-338.5px -2.5px)(-421px -165px)(-337.5px -271px)(-383px -263px)(-411px -258px)(-415.5px -284.5px)(-384.5px -286.5px)(-445.5px -268.5px)(-410px -300px)(-384px -310.5px)(-511.5px -1.5px)(-254px -348px)(-278px -344px)(-308px -350px)(-326px -350px)(-348px -336px)(-388.5px -332.5px)(-424px -337px)(-401px -385px)(-393.5px -474px)(-171px -407.5px)(-32.5px -408.5px)(-477px -514px)(-514px -385.5px)(-853px -378.5px)(-445.5px -268.5px));
$widths : 298px, 39px, 36px, 90px, 95px, 73px, 90px, 161px, 68px, 44px, 20px, 22px, 15px, 23px, 41px, 30px, 19px, 385px, 16px, 26px, 14px, 13px, 35px, 29px, 39px, 89px, 60px, 210px, 107px, 35px, 338px, 50px, 41px;
$heights: 257px, 65px, 36px, 94px, 94px, 75px, 90px, 157px, 69px, 47px, 20px, 22px, 15px, 23px, 41px, 30px, 19px, 379px, 17px, 26px, 14px, 13px, 34px, 48px, 40px, 85px, 71px, 130px, 124px, 34px, 158px, 173px, 41px;
@for $i from 1 through length($positions) {
.#{nth($classes, $i)}{
@extend .sprite;
background-position:nth($positions, $i);
width:nth($widths, $i);
height:nth($heights, $i);
background-image:url('spriteSheet.png');
margin-top: 1.5em;
&:after{
@extend .spriteLabel;
content:nth($classes,$i);
}
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment