Skip to main content
Participant
August 27, 2014
Question

writing a script to process a sorted photos folder

  • August 27, 2014
  • 0 replies
  • 192 views

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!

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!

    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)

Thanks a lot!

Stav

This topic has been closed for replies.