• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Applying Alpha Channels (AppleScript)

Community Beginner ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

I'm trying to apply alpha channels to certain images. I figured out how to apply alpha channels as a clipping path. However, I would like to apply the alpha channel the way you would in the image import options dialog because it looks much better. Below is what I have so far (the part that would apply alpha channels is the only thing not working). Any help would be greatly appreciated!

-----------------------------------------------------------------------------------------

--ALERTS INFO

-----------------------------------------------------------------------------------------

set success_dialog to "CLIPPING PATHS APPLIED" & return & "All available Photoshop Clipping Paths have been applied." as string

set error_dialog to "ERROR" & return & "There was an error. Some available Photoshop Clipping Paths may not have been applied." as string

set start_dialog to "CHECKING PATHS" & return & "This script is now applying the Photoshop Clipping Paths." as string

-----------------------------------------------------------------------------------------

--SETTING INDESIGN PREFERENCES

-----------------------------------------------------------------------------------------

--Setting measurements to inches

tell application "Adobe InDesign CC 2017"

  tell view preferences

  set horizontal measurement units to inches

  set vertical measurement units to inches

  end tell

  -----------------------------------------------------------------

  --LOOPING THROUGH EVERY IMAGE IN THE DOCUMENT

  -----------------------------------------------------------------

  --Notifying the user that the script is starting

  display alert start_dialog

  --Getting every image in the document

  tell active document

  set my_images to all graphics

  -----------------------------------------------------------------

  --APPLYING ALPHA CHANNELS TO PEOPLE IMAGES

  -----------------------------------------------------------------

  --Determining if there is an alpha channel

  try

  repeat with my_image in my_images

  set alpha_names to alpha channel path names of contour options of text wrap preferences of my_image

  if (alpha_names as string) is not "" then

  --Getting the name of the image

  set link_name to name of item link of my_image as string

  set link_path to file path of item link of my_image as string

  --Getting the square inches of the image (larger images would have people in them)

  set image_frame to parent of my_image

  set x1 to item 1 of geometric bounds of my_image

  set y1 to item 2 of geometric bounds of my_image

  set x2 to item 3 of geometric bounds of my_image

  set y2 to item 4 of geometric bounds of my_image

  set image_width to (x2 - x1)

  set image_height to (y2 - y1)

  set image_square_inches to (image_width * image_height)

  set image_frame_id to id of image_frame

  --Setting the image to an alpha channel if the image name contains certain people photo keywords or is over a certain size

  if link_name contains "Model" or link_name contains "Lifestyle" or link_name contains "Boy" or link_name contains ¬

  "Girl" or image_square_inches is greater than 15 then

  (*******************************************************

   *******************************************************

   *******************************************************

  --(CODE TO ADD ALPHA CHANNEL AS MASK WOULD GO HERE)

  place link_path as alias on rectangle id image_frame_id of page 1 with properties {contour options:{contour type:alpha channel, contour path name:(item 1 of alpha_names)}}

-->Trying to place image with properties above since the image import options dialog comes up only when placing the image

   *******************************************************

   *******************************************************

   *******************************************************)

  -----------------------------------------------------------------

  --APPLYING CLIPPING PATHS TO PRODUCT IMAGES

  -----------------------------------------------------------------

  --Applying the clipping path if the image has an alpha channel but is not a photo of a person

  else

  my apply_clipping_paths(my_image) -->Calling apply clipping path function (see bottom of script)

  end if

  --Applying the clipping path if the image either has no alpha channel

  else

  my apply_clipping_paths(my_image) -->Calling apply clipping path function (see bottom of script)

  end if

  end repeat

  -----------------------------------------------------------------

  --DISPLAYING SUCCESS OR ERROR ALERT TO THE USER WHEN DONE

  -----------------------------------------------------------------

  --Displaying success dialog if everything is ok

  display alert success_dialog

  --Displaying error dialog if something went wrong

  on error

  display alert error_dialog

  end try

  end tell

end tell

-----------------------------------------------------------------

-----------------------------------------------------------------

--FUNCTIONS

-----------------------------------------------------------------

-----------------------------------------------------------------

--Function to apply Photoshop clipping paths

on apply_clipping_paths(the_image)

  tell application "Adobe InDesign CC 2017"

  set path_names to photoshop path names of clipping path of the_image

  if (count of items of path_names) > 0 then

  set properties of the_image to {clipping path:{applied path name: (item 1 of path_names), clipping type:photoshop path}}

  end if

  end tell

end apply_clipping_paths

TOPICS
Scripting

Views

655

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

I think you want to post in the Scripting forum.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2017 Sep 19, 2017

Copy link to clipboard

Copied

--Function to apply Photoshop clipping paths

on apply_clipping_paths(the_image)

  tell application "Adobe InDesign CC 2017"

  set path_names to photoshop path names of clipping path of the_image

  if (count of items of path_names) > 0 then

  set properties of the_image to {clipping path:{applied path name: (item 1 of path_names), clipping type:photoshop path}}

  end if

  end tell

end apply_clipping_paths

Looks like you want:

set path_names to alpha channel path names of clipping path of the_image

--not photoshop path names

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 03, 2017 Oct 03, 2017

Copy link to clipboard

Copied

Looks like you want:

set path_names to alpha channel path names of clipping path of the_image

--not photoshop path names

I had tried that, but it adds the alpha channel as a clipping path, which looks kind of rough. By hand, I'm able to go into the image import options when I first import the image and select the alpha channel there, which looks much smoother than applying it as a clipping path. Maybe that's not an option through AppleScript?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2017 Oct 03, 2017

Copy link to clipboard

Copied

I'm traveling so I can test this,  but I think you also need the clipping type to be alpha channel when you set the image properties

  set path_names to alpha path names of clipping path of the_image

  if (count of items of path_names) > 0 then

  set properties of the_image to {clipping path:{applied path name: (item 1 of path_names), clipping type:alpha channel}}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Nov 10, 2017 Nov 10, 2017

Copy link to clipboard

Copied

LATEST

Moved to InDesign Scripting​

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines