Hello,
I've run into the ScriptUI limitation, in terms of image data, when displaying an Image object in a Window:
Code: Select allvar w = new Window ("dialog", "Flower");
var flower = w.add ("image", undefined, File ("~/Desktop/flower.jpg"));
w.show();
The above works as long as the image is JPG or PNG.
I was wondering whether there's a way to display an image thumb (which is what I actually need) of other formats with Bridge scripting called via bridgeTalk - I'm not too much into Bridge things...
Any suggestion is appreciated!
By the way, while looking around for a solution to my problem I've found this Marc Autret Image prototype hack that's helpful to scale proportionally Images - it's quite useful imho so I might share it here
Code: Select allImage.prototype.onDraw = function() { // written by Marc Autret
// "this" is the container; "this.image" is the graphic
if( !this.image ) return;
var WH = this.size,
wh = this.image.size,
k = Math.min(WH[0] / wh[0], WH[1] / wh[1]),
xy;
// Resize proportionally:
wh = [k * wh[0], k * wh[1]];
// Center:
xy = [(WH[0] - wh[0]) / 2, (WH[1] - wh[1]) / 2];
this.graphics.drawImage(this.image, xy[0], xy[1], wh[0], wh[1]);
WH = wh = xy = null;
}
Thanks!
Davide Barranca
http://www.davidebarranca.com
Displaying Image in ScriptUI (Bridge?)
Displaying Image in ScriptUI (Bridge?)
Paul has posted some scripts that use Bridge to generate thumbnails. Here is some code from my code lib that may save you a search. Note I guess it really should check that Bridge is running and not busy.
Code: Select all// adapted from Paul Riggott
var previewFile = new File(Folder.temp+'/ScriptUI.jpg');
if( previewFile.exists ) previewFile.remove();
var success = createPreview( '~/Desktop/Untitled1.psd');// returns true if preview file is created
if( success ) app.load( previewFile );
function createPreview( image ){
var fileName = new File( image );
var preveiwExists = undefined;
var res = undefined;
var bt = new BridgeTalk;
bt.target = "bridge";
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+fileName.toSource()+");");
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
bt.send(500);
return preveiwExists;
function psRemote( sourceImage ){
var f = new File(Folder.temp+ "/scriptUI.jpg");
var Thumb1 = new Thumbnail( sourceImage );
app.synchronousMode = true;
Thumb1.core.preview.preview;
app.synchronousMode = false;
var md = Thumb1.synchronousMetadata;
md.namespace = "http://ns.adobe.com/tiff/1.0/";
var orientation = md.Orientation.replace(/(\w+)(\s+)(.)(\d+)(.)/,"$3$4");
orientation = orientation.replace(/°/,'');
orientation = orientation.replace(/Rotate/,'');
if(orientation == 'Normal') orientation =0;
var bm = undefined;
bm = Thumb1.core.preview.preview;
if(bm.width != undefined) bm = bm.rotate(orientation);
bm = bm.resize(100,BitmapData.bicubicSharper);/* long side in pixels */
bm.exportTo( f,80 );/* jpeg format file, jpeg quality 0-100 */
return f.exists;
};
function myReturnValue(str){
res = str;
preveiwExists = str;
};
};
Code: Select all// adapted from Paul Riggott
var previewFile = new File(Folder.temp+'/ScriptUI.jpg');
if( previewFile.exists ) previewFile.remove();
var success = createPreview( '~/Desktop/Untitled1.psd');// returns true if preview file is created
if( success ) app.load( previewFile );
function createPreview( image ){
var fileName = new File( image );
var preveiwExists = undefined;
var res = undefined;
var bt = new BridgeTalk;
bt.target = "bridge";
var myScript = ("var ftn = " + psRemote.toSource() + "; ftn("+fileName.toSource()+");");
bt.body = myScript;
bt.onResult = function( inBT ) {myReturnValue(inBT.body); }
bt.send(500);
return preveiwExists;
function psRemote( sourceImage ){
var f = new File(Folder.temp+ "/scriptUI.jpg");
var Thumb1 = new Thumbnail( sourceImage );
app.synchronousMode = true;
Thumb1.core.preview.preview;
app.synchronousMode = false;
var md = Thumb1.synchronousMetadata;
md.namespace = "http://ns.adobe.com/tiff/1.0/";
var orientation = md.Orientation.replace(/(\w+)(\s+)(.)(\d+)(.)/,"$3$4");
orientation = orientation.replace(/°/,'');
orientation = orientation.replace(/Rotate/,'');
if(orientation == 'Normal') orientation =0;
var bm = undefined;
bm = Thumb1.core.preview.preview;
if(bm.width != undefined) bm = bm.rotate(orientation);
bm = bm.resize(100,BitmapData.bicubicSharper);/* long side in pixels */
bm.exportTo( f,80 );/* jpeg format file, jpeg quality 0-100 */
return f.exists;
};
function myReturnValue(str){
res = str;
preveiwExists = str;
};
};
Displaying Image in ScriptUI (Bridge?)
Hello Mike,
do you happen to know if it's possible to grab the BitmapData of the Thumbnail.core.preview.preview (or better the Thumbnail.core.thumbnail.thumbnail which is enough for my purposes - a 100x100px image) and send it directly to an 'image' ScriptUI component without resorting to save a temp JPG on disk? I guess it will be way much faster.
I've tried building it more or less this way:
Code: Select allw.img.image = ScriptUI.newImage(Thumb1.core.preview.preview)
but it failed.
By the way, in the code you've posted I've seen (psRemote) that there's this very invocation:
Code: Select allThumb1.core.preview.preview;
without assigning it to a variable - do you know why? Is it a way to build the object?
Thank you!
Davide
do you happen to know if it's possible to grab the BitmapData of the Thumbnail.core.preview.preview (or better the Thumbnail.core.thumbnail.thumbnail which is enough for my purposes - a 100x100px image) and send it directly to an 'image' ScriptUI component without resorting to save a temp JPG on disk? I guess it will be way much faster.
I've tried building it more or less this way:
Code: Select allw.img.image = ScriptUI.newImage(Thumb1.core.preview.preview)
but it failed.
By the way, in the code you've posted I've seen (psRemote) that there's this very invocation:
Code: Select allThumb1.core.preview.preview;
without assigning it to a variable - do you know why? Is it a way to build the object?
Thank you!
Davide
Displaying Image in ScriptUI (Bridge?)
I don't know of a way to avoid writing the temp image file. As far as I know ScriptUI only accepts file or resource objects. You are trying to use a Bridge bitmap object.
The code I posted was from Paul so I may be wrong here but I think that the first use of the line
Code: Select allThumb1.core.preview.preview;is to force the thumbnail creation in case Bridge has not already made one.
The code I posted was from Paul so I may be wrong here but I think that the first use of the line
Code: Select allThumb1.core.preview.preview;is to force the thumbnail creation in case Bridge has not already made one.