Skip to main content
Participant
November 5, 2009
Question

Any idea how to test wether the cropBox actually contains art?

  • November 5, 2009
  • 1 reply
  • 1339 views

I'm  exporting large drawings as tiles for a google maps project. I do so by moving the cropBox and exporting the covered area as PNGs. Works great so far but ... since the drawing is kind of organic and does not fill the whole area i'm exporting i have many (most) PNGs be just plain white. These just fill my disk space and i have to have them removed later on anyways. My question is therefore wether there is a way to test (Illustrator CS3 / JavaScript) if the cropBox actually contains/covers anything?

This topic has been closed for replies.

1 reply

Participating Frequently
November 5, 2009

Should work with something like this ...didn't get the time to test so if anything goes wrong post/curse here :

var v_doc = app.activeDocument;

var cropBox = v_doc.cropBox;

function isInsideCropBox() {
    for(j = v_doc.pageItems.length - 1; j >= 0; j--) {
        var t_vBounds = v_doc.pageItems.visibleBounds;
      
        if(Inside(cropBox[0], cropBox[1], t_vBounds[0], t_vBounds[2], t_vBounds[3], t_vBounds[1]) || 
           Inside(cropBox[2], cropBox[3], t_vBounds[0], t_vBounds[2], t_vBounds[3], t_vBounds[1]) ||
           Inside(t_vBounds[0], t_vBounds[1], cropBox[0], cropBox[2], cropBox[3], cropBox[1]) || 
           Inside(t_vBounds[2], t_vBounds[3], cropBox[0], cropBox[2], cropBox[3], cropBox[1])){
            return true;
        } else return false;
    }
}


function Inside( x, y, l, r, b, t ) // x,y coords of the point we want to check if is within rectangle, l - left, r - right, b - bottom, t - top; not quite an ellegant solution but should work for now
{
     var _b = x >= l && x <= r;
     if(y<0 && b<0) _b &= -y <= -b; else _b &= y <= b;
     if(y<0 && t<0) _b &= -y >= -t; else _b &= y >= t;
     return _b;
}

if(isInsideCropBox()) {
    alert("TRUE");
} else {
    alert("FALSE");
}

cheers;