Copy link to clipboard
Copied
I'm looking for a JavaScript for Adobe Illustrator, which will alert me if there are any RGB or Embedded or Low-Resolution (effective dpi below 300) images.
I tried ai and it gives me this code, but this is not working…
Can anyone please suggest, or fix the script.
if (app.documents.length > 0) {
var doc = app.activeDocument;
// 2. Check for RGB images
function checkRGBImages() {
var foundRGB = false;
for (var i = 0; i < doc.placedItems.length; i++) {
var placedItem = doc.placedItems[i];
if (placedItem.file) {
try {
var fileType = placedItem.file.fsName.split(".").pop().toLowerCase();
if (fileType === "jpg" || fileType === "jpeg" || fileType === "png") {
var image = placedItem;
if (image.colorSpace === ColorSpace.RGB) {
foundRGB = true;
break;
}
}
} catch (e) {
// Handle any errors in file access
}
}
}
if (foundRGB) {
alert("There are RGB images in the document.");
} else {
alert("No RGB images found in the document.");
}
}
// 3. Check for low-res images
function checkLowResImages() {
var lowResFound = false;
for (var i = 0; i < doc.placedItems.length; i++) {
var item = doc.placedItems[i];
if (item.file) {
try {
if (item.effectivePPI[0] < 300 || item.effectivePPI[1] < 300) {
lowResFound = true;
break;
}
} catch (e) {
// Handle any errors in file access
}
}
}
if (lowResFound) {
alert("There are low-resolution images in the document.");
} else {
alert("No low-resolution images found in the document.");
}
}
// 4. Check for embedded images
function checkEmbeddedImages() {
var embeddedFound = false;
for (var i = 0; i < doc.placedItems.length; i++) {
if (doc.placedItems[i].embedded) {
embeddedFound = true;
break;
}
}
if (embeddedFound) {
alert("There are embedded images in the document.");
} else {
alert("No embedded images found in the document.");
}
}
// Execute functions
checkRGBImages();
checkLowResImages();
checkEmbeddedImages();
} else {
alert("No document is open.");
}
Copy link to clipboard
Copied
Any suggestions, please…