Author Topic: Just to get the ball rolling  (Read 6326 times)

0 Members and 1 Guest are viewing this topic.

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Just to get the ball rolling
« on: March 27, 2007, 11:26:04 AM »
Our images from the photography department are now clipped by an "out source" and sent back. Here is a script that I have used to convert mode, set the path to clipping path trim unwanted pixel data and save to locations depending on the image area after trim. By doing this clean up and using LZW compression in the save as tif I am able to make considerable file size savings over eps. Don't know if this could be a starting point for any of you! Oh you get a log about the path info too.

Quote
property ImageArea1 : 6000000 -- 6 Mega Pixel
property ImageArea2 : 3000000 -- 3 Mega Pixel
property ImageArea3 : 1000000 -- 1 Mega Pixel
--
set inputFolder to choose folder with prompt "Where are the Images?" without invisibles
set TodaysDate to do shell script "date \"+%d-%m-%y\""
--
tell application "Finder"
     set filesList to files in inputFolder
     set ResizedImages to make new folder at desktop with properties ¬
          {name:"Resized Images " & TodaysDate}
     set LargeImages to make new folder at ResizedImages with properties ¬
          {name:"Large Images"}
     set MediumImages to make new folder at ResizedImages with properties ¬
          {name:"Medium Images"}
     set SmallImages to make new folder at ResizedImages with properties ¬
          {name:"Small Images"}
     set MediumGrayImages to make new folder at ResizedImages with properties ¬
          {name:"Medium Images Grayscale"}
     set SmallGrayImages to make new folder at ResizedImages with properties ¬
          {name:"Small Images Grayscale"}
end tell
--
tell application "Adobe Photoshop CS2"
     set display dialogs to never
     set UserPrefs to properties of settings
     set ruler units of settings to pixel units
end tell
--

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Just to get the ball rolling
« Reply #1 on: March 27, 2007, 11:27:11 AM »
Quote
repeat with aFile in filesList
     set fileIndex to 0
     tell application "Finder"
          set theFile to aFile as alias
          set theFileName to name of theFile
     end tell
     tell application "Adobe Photoshop CS2"
          activate
          open theFile
          set docRef to the current document
          --
          set docName to name of docRef
          set docBaseName to getBaseName(docName) of me
          tell docRef
               if (bits per channel is sixteen) then
                    set bits per channel to eight
               end if
               if (mode is not CMYK) then
                    change mode to CMYK
               end if
               delete (every channel whose kind is not component channel)
               if (count of art layers) > 1 or (count of layer sets) > 0 or ((count of art layers) is 1 and not background layer of layer 1) then flatten
               if exists (path item 1) then
                    set thepath to name of path item 1
                    set subpaths to count of sub path items of path item 1
                    set openPaths to (count of (sub path items whose closed is false) of path item 1) as string
                    set thepoints to 0
                    repeat with x from 0 to (subpaths - 1) -- Java's index starts at "0" Zero
                         do javascript "activeDocument.pathItems[0].subPathItems[" & x & "].pathPoints.length" show debugger on runtime error
                         set pathpoints to the result as string
                         set thepoints to thepoints + pathpoints as string
                    end repeat
                    make clipping path path item 1 flatness 0.3
                    create selection path item 1 feather amount 0 with antialiasing
                    expand selection by 10
                    invert selection
                    fill selection with contents {class:RGB color, red:255, green:255, blue:255}
                    deselect
                    trim basing trim on top left pixel
               else
                    set thepath to "No Clipping Path"
                    set thepoints to "0"
                    set openPaths to "0"
               end if
               writelog(docName, thepath, openPaths, thepoints) of me
               -- Get variables to perform calculations from
               set docHeight to height
               set docWidth to width
               set thisImageArea to docHeight * docWidth
               -- Record a position in history
               set savedState to current history state
               -- Check the current image is larger than target before resize
               if thisImageArea > ImageArea1 then
                    set imagewidth to ((docWidth * ImageArea1 / docHeight) ^ 0.5) as integer
                    set imageheight to (docHeight * imagewidth / docWidth) as integer
                    resize image height imageheight width imagewidth resolution 300
                    set newFileName to (LargeImages as string) & docBaseName & "_Large.tif"
                    save docRef in file newFileName as TIFF with options ¬
                         {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:false, save spot colors:false, embed color profile:true, save layers:false, transparency:false} with copying
                    -- Return to a recorded position in history
                    set current history state to savedState
               end if
               -- Check the current image is larger than target before resize
               if thisImageArea > ImageArea2 then
                    set imagewidth to ((docWidth * ImageArea2 / docHeight) ^ 0.5) as integer
                    set imageheight to (docHeight * imagewidth / docWidth) as integer
                    resize image height imageheight width imagewidth resolution 300
                    set newFileName to (MediumImages as string) & docBaseName & "_Medium.tif"
                    save docRef in file newFileName as TIFF with options ¬
                         {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:false, save spot colors:false, embed color profile:true, save layers:false, transparency:false} with copying
                    --
                    change mode to grayscale
                    set newFileName to (MediumGrayImages as string) & docBaseName & "_Medium_GS.tif"
                    save docRef in file newFileName as TIFF with options ¬
                         {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:false, save spot colors:false, embed color profile:true, save layers:false, transparency:false} with copying
                    -- Return to a recorded position in history
                    set current history state to savedState
               end if
               -- Check the current image is larger than target before resize
               if thisImageArea > ImageArea3 then
                    set imagewidth to ((docWidth * ImageArea3 / docHeight) ^ 0.5) as integer
                    set imageheight to (docHeight * imagewidth / docWidth) as integer
                    resize image height imageheight width imagewidth resolution 200
                    set newFileName to (SmallImages as string) & docBaseName & "_Small.tif"
                    save docRef in file newFileName as TIFF with options ¬
                         {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:false, save spot colors:false, embed color profile:true, save layers:false, transparency:false} with copying
                    --
                    change mode to grayscale
                    set newFileName to (SmallGrayImages as string) & docBaseName & "_Small_GS.tif"
                    save docRef in file newFileName as TIFF with options ¬
                         {class:TIFF save options, image compression:LZW, byte order:Mac OS, save alpha channels:false, save spot colors:false, embed color profile:true, save layers:false, transparency:false} with copying
               end if
          end tell
          close current document without saving
     end tell
end repeat

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Just to get the ball rolling
« Reply #2 on: March 27, 2007, 11:28:22 AM »
Quote
--
tell application "Adobe Photoshop CS2"
     set ruler units of settings to ruler units of UserPrefs
end tell
--
set ReadFile to ((path to desktop folder) as text) & "Path Point Log.txt" as alias
tell application "TextEdit"
     activate
     open ReadFile
end tell
--
on getBaseName(fName)
     set baseName to fName
     repeat with idx from 1 to (length of fName)
          if (item idx of fName = ".") then
               set baseName to (items 1 thru (idx - 1) of fName) as string
               exit repeat
          end if
     end repeat
     return baseName
end getBaseName
--
on writelog(docName, thepath, openPaths, thepoints)
     set theLog to ((path to desktop folder) as text) & "Path Point Log.txt"
     try
          open for access file the theLog with write permission
          write (return & docName & " - " & thepath & " - " & thepoints & " Points - Open Sub Paths " & openPaths) to file the theLog starting at eof
          close access file the theLog
     on error
          try
               close access file the theLog
          end try
     end try
end writelog

Offline changeup

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Just to get the ball rolling
« Reply #3 on: June 27, 2007, 04:32:50 PM »
Larsen, (Whomever else)
I am looking for a similar script.  One that will tell me if a "Path" exists on a photoshop image.  Not concerned with a clipping path or not.  I just need to indicate whether or not there is a path. 

I will have to later inspect the path for accuracy but would like to narrow down my opening up in photoshop.
Would be wonderful if I could drag and drop several files onto the script and get some type of information back.  OSX CS2
Any help much appreciated

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Just to get the ball rolling
« Reply #4 on: June 28, 2007, 08:46:56 AM »
I had a look at this once before and looks very tricky. The only way I know at present is to script opening the files and check for the existence of path items in Photoshop which defeats the idea of what your after. I don't know if Graphic Converter can do this but it can read info from file without opening it. Michel would most likely know if this can be done. I did look into some of the character patterns in images and found a few things about paths I just haven't tried enough to see if its consistent.

clipping path appears to always be "8BIM ?

Offline changeup

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Just to get the ball rolling
« Reply #5 on: June 28, 2007, 12:09:52 PM »
Thanks for the reply - I will check CG
(sorry if this gets posted twice, error posting first time)

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Just to get the ball rolling
« Reply #6 on: June 28, 2007, 12:32:09 PM »
the square box in the above should be ASCII character 183 - summation? how are you paths named? default "Path 1" etc for english install or user input?

Offline changeup

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Just to get the ball rolling
« Reply #7 on: June 28, 2007, 01:13:56 PM »
hmmmm,
Well, I cannot count on a naming consistency for these particular paths.  I would think the "Path 1" would be good but cannot say for sure.  dealing with a variety of vendors.  a bit more complicated...

thanks

Offline larsen67

  • Sr. Member
  • ****
  • Posts: 459
  • Karma: 10
  • Gender: Male
Re: Just to get the ball rolling
« Reply #8 on: June 29, 2007, 04:27:00 AM »
This actually worked better than I expected it to. Just a plain search for "path" space "numbers" worked with the exception of work paths (these are stored by some other means in file that I can't find). I've only had chance to run some basic testing. Other string searches should be easy to add if you find any patterns to the naming. This code requires that you download an OSXA and place in scripting additions folder. You can find this here:
http://www.satimage.fr/software/en/downloads_osaxen_pop.html

001   property type_list : {"8BIM", "BMP ", "EPSF", "GIFf", "JPEG", "PICT", "PCX ", "PNGf", "PXR ", "PRAW", "SCRN", "..CT", "TPIC", "PDF ", "8BPS", "TIFF"}
002   property extension_list : {"bmp", "eps", "gif", "jpg", "pct", "pcx", "png", "pxr", "raw", "rsr", "sct", "tga", "pdf", "psd", "tif"}
003   property path_folder : ""
004   property no_path_folder : ""
005   --
006   global paths_in_image
007   --
008   on open these_items
009        tell application "Finder"
010             if not (exists folder "Images with paths" of desktop) then
011                  set path_folder to make new folder at desktop with properties {name:"Images with paths"}
012             else
013                  set path_folder to folder "Images with paths" of desktop as string
014             end if
015             if not (exists folder "Images without paths" of desktop) then
016                  set no_path_folder to make new folder at desktop with properties {name:"Images without paths"}
017             else
018                  set no_path_folder to folder "Images without paths" of desktop as string
019             end if
020        end tell
021        repeat with i from 1 to the count of these_items
022             set this_item to (item i of these_items)
023             set the item_info to info for this_item
024             if folder of the item_info is true then
025                  process_folder(this_item)
026             else if (alias of the item_info is false) and ¬
027                  ((the file type of the item_info is in the type_list) or ¬
028                       the name extension of the item_info is in the extension_list) then
029                  process_item(this_item)
030             end if
031        end repeat
032        tell application "Finder"
033             activate
034             display dialog "Image sort is done" buttons {"OK"} default button 1 giving up after 30
035        end tell
036   end open
037   -- this sub-routine processes folders
038   on process_folder(this_folder)
039        set theList to list folder this_folder without invisibles
040        repeat (length of theList) times
041             repeat with j from 1 to (length of theList) - 1
042                  if item j of theList > item (j + 1) of theList then
043                       set {item j of theList, item (j + 1) of theList} to ¬
044                            {item (j + 1) of theList, item j of theList}
045                  end if
046             end repeat
047        end repeat
048        set these_items to theList
049        repeat with i from 1 to the count of these_items
050             set this_item to alias ((this_folder as text) & (item i of these_items))
051             set the item_info to info for this_item
052             if folder of the item_info is true then
053                  process_folder(this_item)
054             else if (alias of the item_info is false) and ¬
055                  ((the file type of the item_info is in the type_list) or ¬
056                       the name extension of the item_info is in the extension_list) then
057                  process_item(this_item)
058             end if
059        end repeat
060   end process_folder
061   -- this sub-routine processes files
062   on process_item(this_item)
063        set paths_in_image to {}
064        try
065             set find_paths to find text "Path ([0-9]{1,})" in this_item with regexp and all occurrences
066             repeat with i from 1 to (count of find_paths)
067                  set j to matchResult of item i of find_paths
068                  if paths_in_image does not contain j then
069                       set end of paths_in_image to j
070                  end if
071             end repeat
072             (* set ASTID to AppleScript's text item delimiters
073             set AppleScript's text item delimiters to return
074             set paths_in_image to items of paths_in_image as string
075             set AppleScript's text item delimiters to ASTID
076             set display_dialog to "This file contains the following paths…" & return & return & paths_in_image
077             display dialog display_dialog buttons {"Cancel"} default button 1 giving up after 1 *)
078        on error
079             -- display dialog "No paths were found in this image" buttons {"Cancel"} default button 1 giving up after 1
080        end try
081        tell application "Finder"
082             if paths_in_image is not {} then
083                  move this_item to path_folder
084             else
085                  move this_item to no_path_folder
086             end if
087        end tell
088   end process_item
089   

Offline changeup

  • Newbie
  • *
  • Posts: 9
  • Karma: 0
Re: Just to get the ball rolling
« Reply #9 on: June 29, 2007, 11:02:46 AM »
Larsen,
This is cool, and again thanks for taking time to talk with me.
When I run this it throws all the images into the no paths folder, even if they have paths.  most but not all are coming to me as eps images and so far no consistnecy with naming of the path. 
Any thoughts as to why??
But this would be perfect!