writing a script to process a sorted photos folder on photoshop CS6

269 Views Asked by At

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 SKU Width Hight Series Key 123BLK1 850 1200
123BLK2 1300 1400
123BLK3 1500 600
123BLK4 1900 900 1900 123BLK5 1100 1700
123GRY1 750 1000
123GRY2 900 1800 1800 123GRY3 1200 1500
123GRY4 1400 1300
123GRY5 1100 750

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

There are 1 best solutions below

0
On

Just wrote a code in Python. If somebody knows how to make it in JS for CS6 i'll reall 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)