Photoshop: Resize images & scale strokes?

I cobbled together a script to make @2x and @3x versions of the current @1x document (72dpi) that’s open in Photoshop.

It all works apart from the fact that it doesn’t scale vector strokes:


try
  tell application id "com.adobe.Photoshop"
  set document_1x to the current document
  set fullDocumentPath to (file path of document_1x as text)
  set documentName to name of document_1x
  set documentNameCount to (count of documentName) as text
  set documentBaseName to (items 1 thru ((length of documentName) - 6) of documentName) as string
  set filePath to (items 1 thru ((length of fullDocumentPath) - documentNameCount) of fullDocumentPath) as string

  tell document_1x
  (* Create @2x document *)
  resize image resolution 144
  set newDocument2x to filePath & documentBaseName & "2x" as string
  save in file newDocument2x as Photoshop format appending lowercase extension with copying

  (* Create @3x document *)
  resize image resolution 216
  set newDocument3x to filePath & documentBaseName & "3x" as string
  save in file newDocument3x as Photoshop format appending lowercase extension with copying
  end tell

  close document_1x without saving
  set document_1x to fullDocumentPath
  end tell

  tell application "Finder"
  open newDocument3x & ".psd"
  open newDocument2x & ".psd"
  open document_1x
  end tell
end try

If I resize the images manually (Image > Image Size) I can turn on an option to ‘Scales Styles’ which also scales strokes when resizing.

I’ve worked around it by creating actions for resizing (which scales the strokes) and run the actions from within the script

do action "Scale to 2x" from "Ps Actions"

But ideally I’d like to do it without running separate actions if possible.

Does anyone know how to do this, or if it’s even possible?

Hi,
use javascript inside your applescript.

https://forums.adobe.com/thread/1232471


tell application id "com.adobe.Photoshop"
	tell front document
		do javascript "var idImgS = charIDToTypeID( \"ImgS\" );
				var desc44 = new ActionDescriptor();
				var idRslt = charIDToTypeID( \"Rslt\" );
				var idRsl = charIDToTypeID( \"#Rsl\" );
				desc44.putUnitDouble( idRslt, idRsl, 72.000000 );
				var idscaleStyles = stringIDToTypeID( \"scaleStyles\" );
				desc44.putBoolean( idscaleStyles, true );
				var idCnsP = charIDToTypeID( \"CnsP\" );
				desc44.putBoolean( idCnsP, true );
				var idIntr = charIDToTypeID( \"Intr\" );
				var idIntp = charIDToTypeID( \"Intp\" );
				var idautomaticInterpolation = stringIDToTypeID( \"automaticInterpolation\" );
				desc44.putEnumerated( idIntr, idIntp, idautomaticInterpolation );
			executeAction( idImgS, desc44, DialogModes.NO );"
	end tell
end tell

You can make your own appleScript-Handler with this. For example:


my resizeImageResolution(72, true, true, "automaticInterpolation")

on resizeImageResolution(tmp_resolution, tmp_scaleStyles, tmp_constrainProperties, tmp_interpolation)
	tell application id "com.adobe.Photoshop"
		tell front document
			do javascript "var idImgS = charIDToTypeID( \"ImgS\" );
							var desc44 = new ActionDescriptor();
							var idRslt = charIDToTypeID( \"Rslt\" );
							var idRsl = charIDToTypeID( \"#Rsl\" );
							desc44.putUnitDouble( idRslt, idRsl, " & tmp_resolution & " );
							var idscaleStyles = stringIDToTypeID( \"scaleStyles\" );
							desc44.putBoolean( idscaleStyles, " & tmp_scaleStyles & " );
							var idCnsP = charIDToTypeID( \"CnsP\" );
							desc44.putBoolean( idCnsP, " & tmp_constrainProperties & " );
							var idIntr = charIDToTypeID( \"Intr\" );
							var idIntp = charIDToTypeID( \"Intp\" );
							var idautomaticInterpolation = stringIDToTypeID( \"" & tmp_interpolation & "\" );
							desc44.putEnumerated( idIntr, idIntp, idautomaticInterpolation );
						executeAction( idImgS, desc44, DialogModes.NO );"
		end tell
	end tell
end resizeImageResolution

-- oneliner, replaced '\r' in javascriptString with ' '
on resizeImageResolution_oneLiner(tmp_resolution, tmp_scaleStyles, tmp_constrainProperties, tmp_interpolation)
	tell application id "com.adobe.Photoshop"
		tell front document
			do javascript "var idImgS = charIDToTypeID( \"ImgS\" ); var desc44 = new ActionDescriptor(); var idRslt = charIDToTypeID( \"Rslt\" ); var idRsl = charIDToTypeID( \"#Rsl\" ); desc44.putUnitDouble( idRslt, idRsl, " & tmp_resolution & " ); var idscaleStyles = stringIDToTypeID( \"scaleStyles\" ); desc44.putBoolean( idscaleStyles, " & tmp_scaleStyles & " ); var idCnsP = charIDToTypeID( \"CnsP\" ); desc44.putBoolean( idCnsP, " & tmp_constrainProperties & " ); var idIntr = charIDToTypeID( \"Intr\" ); var idIntp = charIDToTypeID( \"Intp\" ); var idautomaticInterpolation = stringIDToTypeID( \"" & tmp_interpolation & "\" ); desc44.putEnumerated( idIntr, idIntp, idautomaticInterpolation ); executeAction( idImgS, desc44, DialogModes.NO );"
		end tell
	end tell
end resizeImageResolution_oneLiner

Greets
TMA

Wow, that’s great. Thank you so much! :smiley:

If I wanted to resize an image from (for example) @1x (72) to @2x (144), @3x (216) and @4x (288) how would I do it so that I can use most of the code once, instead of copy and pasting the whole thing 4 times?

For example create (something like) 4 lines/variables that would call/run the larger parts of the script below it.
Something like this below (please ignore my ignorance :stuck_out_tongue: )

set resizeImageResolution_1x to (72, true, true, "automaticInterpolation")
set resizeImageResolution_2x to (144, true, true, "automaticInterpolation")
set resizeImageResolution_3x to (216, true, true, "automaticInterpolation")
set resizeImageResolution_4x to (288, true, true, "automaticInterpolation")

Use a List:


set resolutionList to {72, 144, 200}

repeat with tmp_resolution in resolutionList
	my resizeImageResolution(tmp_resolution, true, true, "automaticInterpolation")
	-- do something else like
	-- save...
	-- or...
end repeat

Greets,
TMA

Brilliant, thanks again!