We are working on downloading finished product photo for a website and put it into a custom layer in photoshop. It takes a long time to do manually so i'm trying to see if we can automate the process by downloading the JPEG into a local folder and output the final product into another folder as a JPEG.
Workflow - -Download JPEG into folder -Move to Photoshop file -Replace layer image in photoshop with new downloaded JPEG -Export new photoshop file as a JPEG in output folder (possibly into google drive)
A screenshot of the photoshop file is here. enter image description here
I'm not a coder so I used ChatGPT to do try and build an introductory code and I'm just seeing if it will work.
// Load required modules
const request = require('request');
const fs = require('fs');
// Download the JPEG file from a URL and save it in a local folder
const imageUrl = 'https://example.com/image.jpg';
const downloadFolder = '/path/to/download/folder';
const fileName = 'downloaded_image.jpg';
request(imageUrl)
.pipe(fs.createWriteStream(`${downloadFolder}/${fileName}`))
.on('close', function() {
console.log('JPEG downloaded successfully');
// Open the Photoshop file
const photoshopFile = '/path/to/your/photoshop/file.psd';
const docRef = app.open(new File(photoshopFile));
// Replace the layer image in Photoshop with the new downloaded JPEG
const layerName = 'Layer 1';
const layerRef = docRef.layers.getByName(layerName);
const newLayerRef = docRef.artLayers.add();
newLayerRef.name = layerName;
docRef.activeLayer = newLayerRef;
docRef.selection.selectAll();
docRef.paste();
docRef.selection.deselect();
layerRef.remove();
// Export the new Photoshop file as a JPEG and save it in the output folder
const outputFolder = '/path/to/output/folder';
const outputFileName = 'new_file.jpg';
const jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 8; // adjust the quality as needed
docRef.saveAs(new File(`${outputFolder}/${outputFileName}`), jpegOptions);
docRef.close(SaveOptions.DONOTSAVECHANGES);
console.log('New Photoshop file saved as JPEG');
// Upload the new file to Google Drive (assuming you have authenticated and authorized access)
const { google } = require('googleapis');
const drive = google.drive({ version: 'v3', auth: YOUR_AUTH_TOKEN });
const fileMetadata = { name: outputFileName };
const media = { body: fs.createReadStream(`${outputFolder}/${outputFileName}`) };
drive.files.create({ resource: fileMetadata, media: media, fields: 'id' }, function (err, file) {
if (err) {
console.error('Error uploading file to Google Drive:', err);
} else {
console.log(`New file uploaded to Google Drive with ID: ${file.data.id}`);
}
});
});
I haven't tried it yet I'm just seeing if it's even possible and if i'm on the right track.