2 Replies Latest reply on Aug 26, 2014 7:37 PM by JJMack

    writing a script to process a sorted photos folder

    StavB1

      Hi,

       

      I'm trying to write a script for CS6 to process photos for a website. I have some experience in programing in Python and I looked at some Java scripts for CS6 and can understand the commands and logics.

       

      I thought about this idea for a code.

       

      I have a folder of the pictures, cleaned and after editing process, "Trimmed" of white areas from all sizes and sorted by their SKU which are unique. For example 123BLK1, 123BLK2, 123BLK3 etc..

      The photos were taken from the same place in the same angles same lens and everything.

      Think of an object that found in a the tightest white background possible by his lines.

       

      I found out that after I take a series of pictures and find the longest or highest dimension of all series, If I open a square canvas in a size 5% bigger then the biggest dimension of all series, I get the series perfectly centered and with the right proportions between angles!!

       

      My idea was to make a script that creates a sorted database out the files in the folder and save the biggest dimension out of the series and then open the square canvas in that dimension.

      Like a dictionary database, that the cells will have the pictures names and the key will be the biggest dimension.

      Then, for every picture series, open a square canvas in the size of the key.

       

      For example, if I have these pictures in the folder, the dictionary will sort every 5 SKU with the same number and same color (different angle 1..5), save the biggest dimension in the key and open the square canvas for each series by it's key

      SKUWidthHightSeries Key
      123BLK18501200
      123BLK213001400
      123BLK31500600
      123BLK419009001900
      123BLK511001700
      123GRY17501000
      123GRY290018001800
      123GRY312001500
      123GRY414001300
      123GRY51100750

       

      I'm might be wrong in something here, but if somebody understand my idea and can help me out with the code for a CS6 version I'll really appreciate it!

       

      Thanks a lot!

       

      Stav

        • 1. Re: writing a script to process a sorted photos folder
          StavB1 Level 1

          I wrote a script in Python which I'm familiar with,

           

          If somebody can help me translate it to CS6 JavaScript i'll appreciate it!

           

          Thanks

           

          Stav

           

              import os, sys

              from PIL import Image, ImageTk, ImageFilter, ImageOps

             

              def canvas (path):

                  dic = {}

                  for file in os.listdir( path ):

                      if dic.get(file[:6]) == None:

                          dic[file[:6]] = [file]

                      else:

                          dic[file[:6]]+=[file]

                  for key in dic:

                      dim = None

                      for pic in dic[key]: # find biggest dimmention

                          im = Image.open(path+pic)

                          if dim < max(im.size):

                              dim = max(im.size)

                      for pic in dic[key]: # open square canvas

                          im = Image.open(path+pic,'r')

                          w,h = im.size

                          background = Image.new('L', (dim,dim), "white")

                          background.paste(im,((dim-w)/2,(dim-h)/2))

                          background.save(path+pic)

          • 2. Re: writing a script to process a sorted photos folder
            JJMack Most Valuable Participant

            I think it would be better if you asked in the Photoshop Scripting forum

             

            Someone there may know Python.  Can you export a CVS file that  contains the file name and the size of the canvas you want to place the image in ?

             

            A Photoshop javascript could read that CVS File Open new square documents and place the file into it then save a image file. Close the document and process the next row. Do the same till all new square image files are created.