2

In this example there are 4 shapes drawn on an empty layer, over a solid white background layer. Using the Magic Wand selection tool, I clicked on the empty space on the layer with shapes and then via right-click context menu inverted the selection. Now the selection entirely envelops all 4 shapes, anything unselected is transparent pixels:

From here, I'd like to create a user-defined slice around each separate selection "island", so that each shape is in its own slice, like so (example created manually with help of rulers):

Is there a menu option or a script to do this? Specifically, I want to avoid manually creating layers for each separate shape in cases where there may be tens or hundreds of separate shapes in an image. Basically, I'd like to automate slicing of what can fit under the definition of a "sprite sheet".

2
  • In your example it seems like the shapes are more or less laid out in a pattern. When you have hundreds of shapes are they also following a precise pattern? If they are you could take advantage of that.
    – Wolff
    Dec 8, 2019 at 10:45
  • @Wolff This is just a quick example I mocked up, but I'm looking for a solution for the generic case where separate shape size and placement can be absolutely random. It's going to be easier to edit the results than to have to manually pre-configure the script/algo to create the correct result, in my view. Dec 8, 2019 at 18:04

3 Answers 3

3

I've made a script to split a layer to separate islands, it might help:

enter image description here

It' a part of a free Scriptorator scripts pack. Then you can run Layer > New Layer Based Slice from the top menu to create slices based on the result.

enter image description here

5
  • Looks like exactly what I wanted! Where can I examine the source code for the scripts? I'm having a hard time finding them in the Bitbucket repo. Dec 8, 2019 at 18:09
  • The Bitbucket repo is for the manual only, the scripts are available as binaries on my Gumroad. Dec 8, 2019 at 18:39
  • Ah, see, I don't trust binaries without being able to inspect the source code myself. Maybe there is something I can improve, or maybe there is unwanted third-party tracking which is always a concern with black box binaries. It's always preferable to be able to inspect the source code and build it locally. Dec 9, 2019 at 6:04
  • Why do you use Photoshop then? Don't think you can build it locally. The reason I use binaries is that I use the same libraries in commercial products and there're a lot of time invested in those. But of course, it's your choice. Dec 9, 2019 at 7:13
  • Asking individual users for source code of scripts and asking multi-million dollar corporations for sources of their products is a bit different. Also, software licenses are different, and I prefer using free sources whenever possible. Because when a third-party closed-source site inevitably stops working after just a few years, the download links will be gone and it won't be possible to find the files linked in the answer. But if the code is contained in the answer, it's a much more resilient, and therefore more valuable contribution to a Q&A site such as this. Dec 10, 2019 at 6:37
2

Here is a semi-manual method with some help from an Action.

  • Use Magic Wand to select one of the shapes. Adjust the Sample Size and Tolerance settings. The selection doesn't have to be perfect.
  • Create a new Action, set a Function Key like F3 (without Shift or Control) and start recording.
  • Use Select > Modify > Expand and choose an Expand By value which is high enough to make sure that all pixels of the shape are selected, but low enough to make sure that the selection doesn't overlap other shapes.
  • Right-click the selection and choose Layer Via Cut.
  • (Optionally hide the new layer to make it easier to see the progress.)
  • Select the original layer with the shapes.
  • Stop recording.
  • Now for each shape: Click with Magic Wand on the shape and press F3 (or whatever you chose).
  • Delete the now empty original layer.
  • Use File > Export > Layers to Files to export all layers as separate PNGs. Check Trim Layers to make sure that the transparent background is cropped away.

0
  • Make a different layer for each shape
  • Select all layers and go to menu View > New Guides From Shape
  • Select the Slice Tool and click the Slice From Guides button
1
  • How do I make different layers for each shape for a case like this, but let's say I have a hundred separate shapes like this, so I don't have to "Layer via Cut" each of them manually? Dec 8, 2019 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.