Accessing Bridge thumbnail image?

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

Mike Hale

Accessing Bridge thumbnail image?

Post by Mike Hale »

I ran across a blog post that says that makes it sound like there is a script that will sent an email using the thumbnail, no the full image. So it can send a small jpeg without needing to resize and/or convert formats in photoshop.

I don't want to email but I like the idea of getting a small jpeg version of an image.

Anyone have any idea of how that is done. I don't do much Bridge scripting. I know how to point Bridge at a file and access the thumbnail. It the getting the thumbnail image that has be at a loss.

Mike
xbytor

Accessing Bridge thumbnail image?

Post by xbytor »

Here's some code from a script I wrote. It saves a Thumbnail as a jpeg. The parameters should be obvious. There may be stuff missing, but this should get you pointed in the right direction.

-X

Code: Select allBridgeLib.saveAsJPEG = function(th, file, width, height, quality) {
  var bm = new BitmapData(th.spec);
  var ns = "http://ns.adobe.com/tiff/1.0/";
  var rc = false;

  try {
    if (th.hasMetadata) {
      // this lovely bit of code handles images that are rotate
      // in the metadata but not on the disk
      var md;
      if (DEV) {
        md = th.metadata;
      } else {
        md = th.synchronousMetadata;
      }

      if (md) {
        md.namespace = ns;
        var rotate = md["Orientation"];

        if (rotate && rotate.match(/rotate/i)) {
          var m = rotate.match(/(-)?(\d+)/);
          if (m) {
            var deg = toNumber(m[2]);
            if (m[1] == '-') {
              deg = -deg;
            }

            var nbm = bm.rotate(deg);
            if (nbm) {
              bm = nbm;
            }
          }
        }
      }
    }
  } catch (e) {
    var msg = Stdlib.exceptionMessage(e);
    Stdlib.log(msg);
    alert(msg);
    return false;
  }

  if (height == undefined) {
    height = width;
  }

  if (width) {
    var size = width;

    if (width != height) {
      var rat = height/width;
      var irat = bm.height/bm.width;

      // var size;
      if (rat > irat) {
        size = Math.max(width, Math.floor(width * irat));

      } else {
        size = Math.max(height, Math.floor(height/irat));
      }
    }

    var nbm = bm.resize(toNumber(size));
    if (nbm) {
      bm = nbm;
    }
  }

  file.remove();
  bm.exportTo(file, quality);

  var rc = BridgeLib.waitForFile(file, BridgeLib.DEFAULT_BT_TIMEOUT);
  return rc;
};

BridgeLib.waitForFile = function(file, timeout) {
  var parts = 20;

  if (timeout > 20) {
    parts = Math.ceil(timeout/2);
  }

  var timer = (timeout / parts) * 1000;

  while (!file.exists && parts) {
    $.sleep(timer);
    parts--;
  }

  return file.exists;
};
Paul MR

Accessing Bridge thumbnail image?

Post by Paul MR »

There is an example here as well Mike.
bb/viewtopic.php?t=2741
Mike Hale

Accessing Bridge thumbnail image?

Post by Mike Hale »

Thanks guys. One last question( I hope ). If I don't care about rotating can I skip the metadata and get jpegs of non bitmaped docs like ai, indesign, pdf, etc?
Paul MR

Accessing Bridge thumbnail image?

Post by Paul MR »

Have a look at this and see if it will fit the bill....
http://www.adobe.com/cfusion/exchange/i ... ome&exc=20 ... ome&exc=20

BridgeExportToJpegCS4
xbytor

Accessing Bridge thumbnail image?

Post by xbytor »

Paul MR wrote:Have a look at this and see if it will fit the bill....
BridgeExportToJpegCS4

Uh, that's an interesting script. But it does show how to get at the thumbnails and previews directly of they're available.

And the FileRenamer code looks like an interesting approach to that problem.

-X
Mike Hale

Accessing Bridge thumbnail image?

Post by Mike Hale »

Paul MR wrote:BridgeExportToJpegCS4Now I do feel stupid. I had looked at that script before I made my post. I think that I confused jsxinc with jsxbin and thought the code that did the work was not viewable.