Using Chat GPT to automate for an Ecommerce Store (1/3)
Here is the context
I have an ecommerce store I am building
I want to have JPEG's with black background of images to display on the website that are smaller so take up less room and load faster then when the customer is ready I then combine corresponding transparent PNG files to be displayed on a mockup.
To achieve this making use of
Photoshop Actions
Photoshop Scripting (Javascript) JSX Files
PHP
Shopify Liquid (I have a programmer doing this)
Chat GPT 4 with Data Analysis Module
This first video was where I wanted to experiment with Jpeg formats to see what combination of factors would work well with regards three factors
  1. % reduction from 20 to 50% of original size
  2. Jpeg quality level (Jpeg is a lossy compression method so quality determines the amount of loss you are happy with from 8 to 12)
  3. Interpolation Method - there are various methods the image can be compressed.
Here is a short video of creating the JSX file and then running it in Photoshop
Here is my final code (with some additional comments)
// Define the input file and output folder <- this is a comment
var inputFile = new File("<Path to a file on my system>");
var outputFolder = new Folder("./JpegTest");
// If the output folder does not exist create it:
if (!outputFolder.exists) {
outputFolder.create();
}
// Possible quality levels and interpolation methods
var qualityLevels = [8, 9, 10, 11, 12];
var interpolationMethods = ["BICUBIC", "BICUBICSMOOTHER", "BICUBICSHARPER", "BILINEAR", "NEARESTNEIGHBOR"];
// Possible resize percentages
var resizePercentages = [20, 30, 40, 50]; // Resize to 20%, 30%, 40%, 50% of the original size
// Loop through quality levels, interpolation methods, and resize percentages
for (var i = 0; i < qualityLevels.length; i++) {
for (var j = 0; j < interpolationMethods.length; j++) {
for (var k = 0; k < resizePercentages.length; k++) {
// Open the file each time to start fresh
var docRef = open(inputFile);
// try to resize the image
try {
// Initialize JPEG save options
var jpgSaveOptions = new JPEGSaveOptions();
// Set JPEG quality and interpolation method
jpgSaveOptions.quality = qualityLevels[i];
// Resize the image
var newWidth = docRef.width * (resizePercentages[k] / 100);
var newHeight = docRef.height * (resizePercentages[k] / 100);
docRef.resizeImage(newWidth, newHeight, docRef.resolution, ResampleMethod[interpolationMethods[j]]);
// Save the file
var fileName = resizePercentages[k] + "_" + qualityLevels[i] + "_" + interpolationMethods[j] + ".jpg";
var outputFile = new File(outputFolder + "/" + fileName);
docRef.saveAs(outputFile, jpgSaveOptions, true, Extension.LOWERCASE);
// what to do if resizing the iamge fails
} catch (e) {
//displayan errorr to the console detailing which part it had issues with (if you want to display to the screen use alert in place of writeLn
$.writeln("Error in saving JPEG with quality " + qualityLevels[i] + " and interpolation " + interpolationMethods[j] + ": " + e.toString());
} finally {
// Close the document without saving changes
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
}
}
}
5
5 comments
Paul Cowen
4
Using Chat GPT to automate for an Ecommerce Store (1/3)
Content Academy
Public group
Build a profitable content strategy, efficient team & automated process
Leaderboard (30-day)
powered by