In This Edition:
- Can ChatGPT write code?
- Humans need a Label
Can ChatGPT write code?
Continuing on last month's sermon about these new "AI" machine learning tools used to generate images, I also thought I'd give ChatGPT a chance to help me with a programming need. I had a folder with 500 images in it of various sizes and formats, and wanted to shrink just some of them and save them to a different directory using the original file type. You can't use Photoshop actions for this because it lacks the ability to do an "IF - THEN".
So I asked this question of ChatGPT and my jaw dropped when I saw its response:
===
Me: Can you write a Photoshop script that goes through every image in a folder, shrinks an image to 6" wide at 72 dpi only if the original image is larger than that, then save it in a different directory as either a .jpg of quality 4 or a .png file of smallest size depending on what kind of file the original image was?
ChatGPT: Here is a sample script in Adobe Photoshop's scripting language, JavaScript, that accomplishes the task you described. The script can be run using Adobe Photoshop's scripting functionality, which can be accessed through the "File" menu. The code it gave me appears in the scrollbox below:
// Specify the source folder
var srcFolder = Folder.selectDialog("Select the source folder");
// Specify the destination folder
var dstFolder = Folder.selectDialog("Select the destination folder");
// Get a list of all files in the source folder
var fileList = srcFolder.getFiles();
// Loop through each file in the source folder
for (var i = 0; i < fileList.length; i++) {
// Open the current file
var file = fileList[i];
if (file instanceof File && file.hidden == false) {
app.open(file);
// Check if the image is wider than 6 inches at 72 DPI
if (app.activeDocument.width > (6 * 72)) {
// Calculate the new width in pixels
var newWidth = 6 * 72;
// Resize the image
app.activeDocument.resizeImage(UnitValue(newWidth, "px"), null, 72, ResampleMethod.BICUBIC);
// Get the file extension of the original image
var fileExtension = app.activeDocument.name.split(".").pop().toLowerCase();
// Compose the new file name
var newName = dstFolder.fsName + "/" + app.activeDocument.name.split(".")[0] + "_resized." + fileExtension;
// Save the resized image
if (fileExtension == "jpg") {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 4;
app.activeDocument.saveAs(new File(newName), jpgSaveOptions, true, Extension.LOWERCASE);
} else if (fileExtension == "png") {
var pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.compression = 0;
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(new File(newName), pngSaveOptions, true, Extension.LOWERCASE);
}
}
// Close the current document
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
I was gobsmacked when I saw it spit out perfect-looking code - complete with comments!! But my enthusiasm waned when I ran the program.
"This code doesn't work" I protested to the chatbot. "The destination directory is empty, even though it looked like everything ran properly." ChatGPT went into "blame the victim" mode, suggesting that perhaps I didn't have permission to write files there. (I did.)
So I spent the better part of the day debugging the program. And I found that ChatGPT had made a common beginner's mistake: the default units of measurement for some functions were sometimes in inches and sometimes in pixels. So all of the images tested were thought to be the wrong size and so the conditional commands were never executed.
I went back to ChatGPT and we had this conversation:
Me: The units were wrong. Sometimes the image width was measured in inches; sometimes it was measured in pixels.
ChatGPT: You can modify the script to handle both cases. Here's a modified version of the script that takes into account the units of the original image width:
// Specify the source folder
var srcFolder = Folder.selectDialog("Select the source folder");
// Specify the destination folder
var dstFolder = Folder.selectDialog("Select the destination folder");
// Get a list of all files in the source folder
var fileList = srcFolder.getFiles();
// Loop through each file in the source folder
for (var i = 0; i < fileList.length; i++) {
// Open the current file
var file = fileList[i];
if (file instanceof File && file.hidden == false) {
app.open(file);
// Get the width of the image in pixels
var originalWidth = app.activeDocument.width.as("px");
// Check if the image is wider than 6 inches at 72 DPI
if (originalWidth > (6 * 72)) {
// Calculate the new width in pixels
var newWidth = 6 * 72;
// Resize the image
app.activeDocument.resizeImage(UnitValue(newWidth, "px"), null, 72, ResampleMethod.BICUBIC);
// Get the file extension of the original image
var fileExtension = app.activeDocument.name.split(".").pop().toLowerCase();
// Compose the new file name
var newName = dstFolder.fsName + "/" + app.activeDocument.name.split(".")[0] + "_resized." + fileExtension;
// Save the resized image
if (fileExtension == "jpg") {
var jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 4;
app.activeDocument.saveAs(new File(newName), jpgSaveOptions, true, Extension.LOWERCASE);
} else if (fileExtension == "png") {
var pngSaveOptions = new PNGSaveOptions();
pngSaveOptions.compression = 0;
pngSaveOptions.interlaced = false;
app.activeDocument.saveAs(new File(newName), pngSaveOptions, true, Extension.LOWERCASE);
}
}
// Close the current document
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
THAT worked!
Moral to the story #1: This stuff won't put programmers out of work, but it will save them a considerable amount of time by quickly producing code they can tweak. (That's no different from how programmers do their job now: Search Google for a code fragment (usually from from StackOverflow.com) and tweak from there.)
Moral to the story #2: Garbage in, garbage out. Chatbots only mirror what's on the internet, which has grown to become a cesspool of ignorance with some chemtrails thrown in. And it's about to get worse... read on.
Humans Need a Label
As a self-referential joke, I asked MidJourney to design a logo certifying that something was "A.I.-free". Of course it couldn't do the lettering right. I wanted it to say, "The Order of Flesh and Blood", a title taken from the 1950's science fiction movie The Creation of the Humanoids. |
For photographers chatgpt isn't a problem, but text-to-image AI such as Midjourney. You can create e.g. perfect portraits in just seconds from scratch. No difference to studio. Just try it out. Both, AI and "real photos" are some kind of art - but needs to be identified in future.
ReplyDeleteDid you read last month's blog post, by chance? https://friedmanarchives.blogspot.com/2023/01/ai-alarmists-are-worried-about-wrong.html
DeleteGreat article. I have had similar thoughts. Photography is a lost cause I think. The manipulation if pixels will get more and more subtle where it becomes next to impossible to tell how much manipulation has occurred.
ReplyDeleteIt's a good thing I invented that digital camera whose output could be authenticated that nobody wanted. https://friedmanarchives.blogspot.com/2020/03/i-invented-camera-whose-output-could-be.html
DeleteRemember where photography began. It was a progression from pinhole projections on canvas for painters, upside down images that artists did not realize contributed to their right brain technique. Then the first cameras were the evolution of projections on canvas to ultimately being projections on paper.
ReplyDeleteThen the first photographers mimicked painting and were called pictorialists. It wasn’t til the f64 movement that the camera pushed the envelope on fulfilling the machine’s potential.
Today we are fulfilling the digital machine’s potential both in camera and in post. Human need for instant gratification aside, we are the artists in all of the above history. And we still are!
I love a good 30,000-foot view! Thanks for this perspective.
DeleteOof, Peter Lik might not be the best name to invoke for photographic purity. The guy clearly photoshops the hell out of his images and often claims they were done in a single shot on film, with no retouching. I remember when his "Bella Luna" shot was on display in his gallery in Vegas. The caption at the time read that he peeked out of his tent in the cold night and was astonished by the moon rising over the mountains. He raised his camera to his eye and took a single shot to immortalize the moment forever. This is the "single photo" he took: https://lik.com/products/bella-luna
ReplyDeleteUhh, gee, that's a very clear moon for being a handheld shot at that zoom level. Also... why is the purple atmospheric haze BEHIND the moon?
Anyway, you might have meant it as a tongue-in-cheek or sarcastic reference, in which case I apologize for reading it wrong.
I agree with you, which is why I used the phrase "perceived as being a photographic god". I hadn't seen that moon shot before but I doubt his mythological explanation of the shot is true; the actual moon is about a zillion times brighter than a star-lit sky at dawn and it surely exceeds the dynamic range of even a specialty film; plus it's hard to believe that a telephoto lens of that strength (I'm guessing 1000mm) has enough depth-of-field to get both the moon and the tree in focus. It's a beautiful image, though, and I have to hand it to Peter for marketing his work so effectively.
ReplyDeleteThat's actually a really sharp logo. Pity the text isn't on a separate layer of the image, so it could be replaced (by a human) with what you originally wanted.
ReplyDelete