Photoshop action : flexagon

christmas is a good time for doing stuff with the kids and we’ve been playing around with a few paper toys.

flexagons are groovy little things but they’re a real bugger to set out the artwork for. so here’s a photoshop template and action to do the difficult bits. if you don’t know what a flexagon is, check out this demo from dutchpapergirl, who also shows how to score, fold and glue the finished product.

the blank template looks like this :
screen grab of blank template

just place your artwork in a single layer behind the 3 hexagonal windows. the artwork layer needs to be ‘flattened’ — if it is just graphics with a transparent background, the action won’t work properly :
screen grab of loaded template

then ensure your artwork layer is selected in the layers panel and run the action to rearrange the various bits :
screen grab of finished layout

be aware that only the front faces of the flexagon display your original artwork :
screen grab of front faces

you get a different result if you flip the flexagon over :
screen grab of reverse faces

those funky snowflakes are based on artwork created by the talented chris spooner, who can be forgiven for drawing 8-ray snowflakes because he’s offering the vectors for free download.

you can download the photoshop template and action here.

and if you like mucking about with paper toys like the flexagon, you should also check out the crazy paper thing.

macgrunt icon

image processing with applescript III

a little while ago we had a look at how to use applescript and sips to scale image files without the hassle of going through photoshop – see image processing with applescript II. open the terminal application, type in “man sips” and you’ll find there’s a whole bunch stuff you can do with images without ever opening photoshop — pretty cool :
screen grab of the sips manual in terminal

… but you can play around with all that another time. today we’re focussing on extending the functionality of the image resize script from that post to make it a little more user friendly. rather than a have script that’s hard-wired to scale images to 500px high, we’ll create one that can accept user input, so that the pixel dimensions can be changed each time the script is run.

to do that we need to first create a dialog. unfortunately the dialog possibilities with standard applescript are pretty crap — particularly when compared to all the options available to applescript dialogs in InDesign – border panels, columns, rows, checkbox controls, dropdowns, enabling groups, event listeners, comboboxes, editboxes, radiobuttons, etc.

here is all you get with standard dialogs :
screen grab of dialog entry in standard additions dictionary

well, although that’s pretty diabolical, it’s still enough for what we need. here’s the first part of the script :

display dialog "enter the pixel ratio you want these scaled to" with title "resize images" default answer "800" buttons {"cancel", "wide", "high"} default button 1
set mgResult to result
set mgText to text returned of mgResult
set mgButton to button returned of mgResult

that’ll give us a dialog something like this :
screen grab of resize images script dialog

… which gives us two pieces of information — the text entered and the button clicked – both captured into variables. if you want to make the script fool-proof, you’ll need to add some error handling to ensure that the text entered is an integer. but in its current form, the script assumes that the user is not an idiot.

the next part of the script creates a subfolder in the finder to save the transformed images into (this script creates duplicates of the original images rather than overwriting the originals with the resized versions) – then creates a reference to that folder for use later in the script :

set mgFolder to (mgText & "px") as string

tell application "Finder"
  set mgItems to selection
  set mgContainer to container of item 1 of mgItems
  set mgContainer to mgContainer as alias
  if (exists folder mgFolder of folder mgContainer) is false then
    make folder at mgContainer with properties {name:mgFolder}
  end if
end tell

set mgFinalFolder to mgContainer & mgFolder & ":" as string

then comes the key to the adaptability of this script — altering the final sips command based on the user’s choices in the dialog. we capture this into a variable called mgScriptString :

if mgButton is "high" then
  set mgScriptString to "sips --resampleHeight '" & mgText & "' "
else
  if mgButton is "wide" then
    set mgScriptString to "sips --resampleWidth '" & mgText & "' "
  end if
end if

the rest of the script is pretty much as per the previous post except that we insert the mgScriptString variable into the do shell script command :

repeat with mgItem in mgItems
  set mgName to name of mgItem
  set mgFinalpath to mgFinalFolder & mgName
  set mgPath to POSIX path of (mgItem as text)
  
  --convert mgFinalpath to POSIX form
  set text item delimiters to ":"
  set mgFinalpath to text items 2 thru -1 of mgFinalpath
  set text item delimiters to "/"
  set mgFinalpath to mgFinalpath as string
  set text item delimiters to ""
  
  set mgFinalpath to quoted form of mgFinalpath
  
  try
    do shell script mgScriptString & quoted form of POSIX path of mgPath & " --out " & mgFinalpath
    do shell script "sips -m '/System/Library/ColorSync/Profiles/sRGB Profile.icc' -i " & mgFinalpath
  end try
end repeat

wrap all that in an open handler (and delete the line “set mgItems to selection”) and you’ll have a script that looks like this :
screen grab of finished script

save that as an application and whack it in your sidebar. drag and drop as many images as you like onto the app — they’ll all be scaled quicker than you could do it through photoshop. don’t worry about accidentally dropping non-image files — these just get skipped.

you can also go here to get the complete image processing script.

have a good one

macgrunt icon

Photoshop tip : layers

here are a couple of handy tricks for working with layers.

this image is going to be deep-etched. we first have to turn the background layer into an active layer (notice the lock in the layers panel) :
screen grab of initial flattened photoshop file

to achieve that, just double-click the layer. this will open a dialog box asking you to name the layer. if you’re happy to just use the default name (Layer 0) — hold down your option key before you double-click to bypass the dialog. but in this case a different name was applied :
screen grab of file with layer made active

now, we’re only a couple of sentences in and it’s already time for a rant …
if you are going to deep-etch an image, DO NOT DESTROY PIXELS. there is absolutely no good reason for permanently erasing a background. you should always use a mask instead. you can read more about making masks here. masks are created with the mask button at the bottom of the layers panel :
screen grab of masked photoshop file

if you click the new layer button you’ll get a new layer above the currently selected layer or, if no layers are selected, at the top of the layer stack. but if you want the new layer beneath the current one, or at the bottom of the stack, hold the command key as you click :
screen grab showing new layer added

to name a new layer as you create it, just hold the option key as you click the new layer button. this also works if you are duplicating an existing layer by dragging it onto the new layer button (but not if you are duplicating with the right-click method).

now we need to add a logo from another file. first you need the new file in a separate window in front of your working file (so that you can see both files) then just click and drag the layer you want from the new file’s layers panel into your working file. you can also do this with multiple layers (just command-click to select multiple layers) :
screen grab showing one file being dragged onto another

to make things a little easier, hold the shift key as you click and drag. this will place the new layers dead centre :
screen grab showing new art in the centre of the working file

to rename an existing layer, double-click on the name in the layers panel.

macgrunt icon

Photoshop tip : masking

let’s start with a belligerent directive … if you are going to deep-etch an image, DO NOT DESTROY PIXELS. there is absolutely no good reason for permanently erasing a background. you should always use a mask instead. if you make a mistake or change your mind or whatever, it’s easier to alter a mask than it is to reclaim lost pixels. ok, you’ve been warned.

a mask is a non-destructive way to create a transparent or translucent portion of a photoshop layer. the mask appears next to the image in the layers panel. white areas are totally opaque, black areas are totally transparent, and grey areas are somewhere between :
screen grab showing a basic mask

it may be a little easier to see the difference with a red background :
screen grab showing the basic mask with a red background

different images require different approaches to deep-etching. here’s one way to do one kind of image.

we need to get rid of the white background of this image so we can put it on a black background. to start with we can make a quick selection with the magic wand tool or by using the color range command under the select menu :
screen grab showing initial selection

this is not a perfect selection however, because the chrome highlights are white too and have also been selected. if we use this selection as our mask we’ll get big black spaces in our chrome — not pretty. refining the selection is a perfect job for quick mask mode (hit the Q key) :
screen grab showing the initial selection in quick mask mode

zoom in and use your brush tool to paint in the missing areas. you can change the colour and transparency of the quick mask by double-clicking the quick mask tool near the bottom of your tool panel :
screen grab showing the refined selection in quick mask mode

now you can exit quick mask (Q) and create the actual mask by hitting the add layer mask button at the bottom of the layers panel :
screen grab showing initial application of layer mask

well, that’s not quite right — we’ve masked out the bike instead of the background. not to worry, there are at least two easy ways to fix this : either undo and hold your option key as you click the add layer mask button; or click on the layer mask and hit command-i to invert the mask.

now we can see the mask is not quite tight enough — there’s a white halo around the bike. this can be fixed by selecting the layer mask and choosing filter > other > minimum (this example only needed a 1 pixel contraction) :
screen grab showing the minimum filter being applied to the layer mask

the next obvious thing to fix are those shadow areas under the wheels. you can do this by painting directly onto the layer mask with your brush tool, or you could make a selection and fill it with black (again, on the mask itself, not the image) :
screen grab showing a further refined layer mask

the only problem now is those disastrous spokes. let’s have a closer look :
screen grab showing closeup of badly masked spokes

now, you could try patching all that up with a lot of brush and eraser work, but here’s a simpler way. first, use the brush and eraser to completely mask out all the spokes and do a basic cleanup (tip: you don’t actually need to swap between the brush and eraser, you could just swap between a black brush and a white brush — whatever you find easier) :
screen grab showing closeup of cleaned up spokes area

next, disable the layer mask (shift-click on the layer mask) so you can see the original image. and use your pen tool to draw straight paths for each of the spokes :
screen grab showing closeup of spokes area with mask disabled

here are the completed paths with the top layer turned off so you can see them easily :
screen grab showing closeup of spokes area with finished paths

make a new layer, select your brush tool and set it to a fine solid brush (this example uses a 1 pixel, 100% hardness brush), then select your path in the paths panel and choose stroke path from the dropdown menu. if the resulting lines are not quite strong enough you can just stroke the path again with the same settings — try that before opting for a bigger brush :
screen grab showing closeup of spokes area showing new lines

now select the lines by holding down the command key as you click on the layer preview in the layers panel. turn off that top layer and hit command-h (hide selection) so you can see what you’re doing. click on the layer mask and hit delete. if the result isn’t strong enough, just hit delete again :
screen grab showing closeup of spokes area showing new masked spokes

bonza :
screen grab showing completed mask

as mentioned, this is just one way to mask this image. feel free to share your favourite way.

keep grunting.

macgrunt icon

Photoshop tip : action within an action

here’s a tip based on one from a brilliant online resource — Tiny Tutorials. you really should subscribe to that site — it’s awesome.

you can record an action in photoshop. you do it so that you can replicate particular sequences of commands on future images. this is invaluable to anyone interested in streamlining their workflow. if you’re using photoshop and NOT already using actions, you’re probably a loony.

but you probably already knew that. however, you may not already know that you can easily include an existing action in your recording of a new action. the image below shows that, while recording an action (“Screen Grab”), you can click on another action (“yellow highlights) and PLAY it :

screen grab showing how to play an existing action while recording a new action

this results in a “play action…” command being added into your new action :

screen grab showing "play action" command added to new recording

two things to be careful of if you start using this method :
• playing another action during recording WILL actually play that action on the image you’re currently working on; and
• do not move or rename your actions, or the “play action…” command will fail when it can’t find the action to play.

macgrunt icon