Open Image preview
Posted: Sun Dec 24, 2017 9:04 am
good morning
I have this script that allows me to select a folder
and see the previews of the files contained within
There are 2 problems that I would like to solve
the first problem and that sometimes I get this error
and I do not know why this happens
The second is not a real problem
I would like to open the file displayed in the window in photoshop
then create a button to do this.
// SCRIPT
I have this script that allows me to select a folder
and see the previews of the files contained within
There are 2 problems that I would like to solve
the first problem and that sometimes I get this error
and I do not know why this happens
The second is not a real problem
I would like to open the file displayed in the window in photoshop
then create a button to do this.
// SCRIPT
Code: Select all
function main(){
inputFolder = Folder.selectDialog("SELECT FOLDER IMAGE:");
var fileList = inputFolder.getFiles(/\.(jpg|png)$/i);
Image.prototype.onDraw = function(){
// "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;
}
var win = new Window ("dialog", "PREVIEW");
win.pnl1 = win.add('panel', undefined, undefined, {borderStyle:'black'});
win.pnl1.preferredSize=[400,400];
win.Im1 = win.pnl1.add ("image", undefined,fileList[0]);
win.Im1.size = [400,400];
win.pnl2 = win.add('panel', undefined, undefined, {borderStyle:'black'});
win.pnl2.orientation = "row";
win.pnl2.bu2 = win.pnl2.add('button',[110,10,200,30],'BACK');
win.pnl2.bu1 = win.pnl2.add('button',[10,10,100,30],'NEXT');
win.grp100 = win.add('group');
win.grp100.bu1 = win.grp100.add('button', undefined, 'CLOSE', { name: "cancel" });
var PIC = 0;
win.pnl2.bu1.onClick=function(){
//Next picture
if(PIC == fileList.length -1) return;
PIC++;
win.Im1.image = fileList[PIC];
}
win.pnl2.bu2.onClick=function(){
//Previous
if(PIC == 0 ) return;
PIC--;
win.Im1.image = fileList[PIC];
}
win.show();
}
main();