• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JavaScript to check for RGB OR Embedded OR Low-Res images in Illustrator

Participant ,
Sep 30, 2024 Sep 30, 2024

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.");
}

 

TOPICS
How-to , Scripting , SDK , Tools

Views

70

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Participant ,
Oct 01, 2024 Oct 01, 2024

Copy link to clipboard

Copied

LATEST

Any suggestions, please…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines