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

Combine open doc into one image

Community Beginner ,
Jan 19, 2020 Jan 19, 2020

Copy link to clipboard

Copied

Hi All, need help to create script to combine All open doc into one image side by side

example got 3 open Doc (imageA , imageB, imageC) then become

Screen Shot 2020-01-20 at 2.45.24 PM.png

 

i have no idea how to use copy & paste script from activeDocument to new Doc , please help

 

          app.preferences.rulerUnits = Units.MM;
app.preferences.typeUnits = TypeUnits.MM;
var W = new UnitValue (app.activeDocument.width, "mm")*app.documents.length;

var H = new UnitValue (app.activeDocument.height, "mm");
          
     app.documents.add(W,H,300,'My Image',NewDocumentMode.CMYK);
     

 

TOPICS
Actions and scripting

Views

517

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

correct answers 1 Correct answer

Community Expert , Jan 20, 2020 Jan 20, 2020

You can try this. It assumes that all the files have only one layer. If not, you can add what JJ has about creating a merged copy.

#target photoshop
var docA = [];
for(var i=0;i<app.documents.length;i++){
    docA.push(app.documents[i]);
    }
activeDocument = docA[0];
newFile ();
var doc = activeDocument;
for(var i=1;i<docA.length;i++){
    var lastX = doc.layers[0].bounds[2];
    var lastY = doc.layers[0].bounds[1];
    var srcD = app.activeDocument = docA[i];
    var curLayer = srcD.activeLay
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Are all open docs the same width and height, or will these vary?

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
Community Beginner ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Hi Stephen, all is same width and height

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

So it’s just the open document count that will vary? It could be say 2, 3, 4 or more open files that need to be combined side by side? Or is it always 3?

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
Community Beginner ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Hi Stephen, the open document count will vary, need to combined side by side

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

If all are the same size the script should be easy to implement. I would first loop through the open documents to check all canvas are the same number of pixels wide and high if so use the current document list to loop again after open a new document the width and height, paste in the composite of the documents list in. After the first is pasted in the loop adds canvas to house the next image on the right and paste in the image.

 

 

A script to do what you want done would be hard to implement if the image vary in size and you want an acceptable composite.  Photoshop ships with a script that can almost do what you want done. It not hard to create a new document with a Canvas sized to house all the currently open documents. A script could also position the images across the canvas side by side and aligned to the top of the canvas.  However with image having different image heights and width I  do not believe the composite composition will be very appealing. The script that ships with photoshop tries to align the image in some logical way but can not align images you are describing. Because of all the different sizes even  when you use it Collage option.  Here I opened 4 different sized image and used menu File>Automate>Photomerge... to try to make a collage. Photomerge alignment failed. I was able to delete the linked layer masks on the image layers and then position the image across the canvas aligned to the top of the canvas like you want.  Personality I do not like the look.

Capture.jpg

JJMack

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Do all the files contain a single layer?

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

That should not matter  you would just do a select all copy merge the document composite then paste clipboard into the new  added document to the right of existing images in it.

 

You just keep adding canvas to house the  image being pasted in.  

 

When I combine screen captures  I just find the open capture document if it is open. If not I open it the clipboard size and paste. If it is open I add canvas to the bottom  the clipboard height if the clipboard  is wider than the current captures I also add to the documents canvas width then past in the clipboard. It easy to add canvas and past in the clipboard.

 

I align the paste to the bottom they would expand the width on the right  and align to the right.

 

 

/* ==========================================================
// 2013  John J. McAssey (JJMack) 
// ======================================================= */
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.

// I set a shortcut key in my case F5 to this Photoshop script mainly for doing Window screen capturing of:
// desktop displays, Active window and selected area copy to clipboard. The script log the cardboard into a document with the name clipboard. 

/*
<javascriptresource>
<about>$$$/JavaScripts/AppendClipboard/About=JJMack's Append Clipboard into Clipboard document.^r^rCopyright 2014 Mouseprints.^r^rJJMack's Script.^r
NOTE:New Clipboard Document will be open if necessary</about>
<category>JJMack's Script</category>
</javascriptresource>
*/

// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events
app.bringToFront();

if (!documents.length) {
	NewCliboardDoc (); 
	app.activeDocument.suspendHistory('appendClipboard','main(true)'); // New document opened proceed
	}
else { 	//locate Document clipboard
	for (var i=0;i<app.documents.length;i++) { 
		app.activeDocument=app.documents[i];
		if (app.activeDocument.name == "Clipboard"){break;}
		}
	if (app.activeDocument.name != "Clipboard"){
		NewCliboardDoc ();
		app.activeDocument.suspendHistory('appendClipboard','main(true)'); // New document opened proceed
		}
	else {app.activeDocument.suspendHistory('appendClipboard','main(false)'); }	// Old Clipboard Document found
	}

///////////////////////////////////////////////////////////////////////////////
//                            main function                                  //
///////////////////////////////////////////////////////////////////////////////
function main(newFile) {
	// declare local variables
	var orig_ruler_units = app.preferences.rulerUnits;
	app.preferences.rulerUnits = Units.PIXELS;			// Set the ruler units to PIXELS

	try { 
		activeDocument.paste(); 					    // past in clipboard may fail enclose in try
		var LB = app.activeDocument.activeLayer.bounds;	// Get the bounds of the work layer
		var LWidth = (LB[2].value) - (LB[0].value);		// Area width
		var LHeight = (LB[3].value) - (LB[1].value);	// Area height
		// BOTTOMCENTER BOTTOMLEFT BOTTOMRIGHT MIDDLECENTER MIDDLELEFT MIDDLERIGHT TOPCENTER TOPLEFT TOPRIGHT
		if(newFile) {
			app.activeDocument.resizeCanvas(LWidth, LHeight, AnchorPosition.TOPLEFT);
			app.activeDocument.layers[1].remove();
			}
		else {
			if (LWidth>=app.activeDocument.width) {	app.activeDocument.resizeCanvas(LWidth, app.activeDocument.height + LHeight, AnchorPosition.TOPLEFT);}
			else {app.activeDocument.resizeCanvas(app.activeDocument.width, app.activeDocument.height + LHeight, AnchorPosition.TOPLEFT);}
			}
		app.activeDocument.selection.selectAll();		// select all
		// Left('AdLf'); Right('AdRg'); Top('AdTp'); Bottom('AdBt'); Center Horizontal('AdCH'); Center Vertical('AdCV');
		align("AdLf");align("AdBt");					//Align to selection Left bottom
		app.activeDocument.selection.deselect();
		SetViewFitonScreen();
		//app.purge(PurgeTarget.CLIPBOARDCACHE);
		}
	catch(e) { 
		if(newFile) app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
		alert("Clipboard Empty"); 
		}		

	app.preferences.rulerUnits = orig_ruler_units;			// Reset units to original settings
	}
///////////////////////////////////////////////////////////////////////////////
//                           main function end                               //
///////////////////////////////////////////////////////////////////////////////
function NewCliboardDoc () {
	// app.documents.add([width][, height][, resolution][, name][, mode][, initialFill][, pixelAspectRatio][, bitsPerChannel][, colorProfileName])
	var Clipboard = app.documents.add( null, null, 100, "Clipboard", NewDocumentMode.RGB, null, null, null, "sRGB IEC61966-2.1");
	}

function align(method) {
	var desc = new ActionDescriptor();
			var ref = new ActionReference();
			ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
		desc.putReference( charIDToTypeID( "null" ), ref );
		desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
	executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
	};

function SetViewFitonScreen() {
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(charIDToTypeID('Mn  '), charIDToTypeID('MnIt'), charIDToTypeID('FtOn'));
    desc1.putReference(charIDToTypeID('null'), ref1);
    executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};

 

JJMack

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

You can try this. It assumes that all the files have only one layer. If not, you can add what JJ has about creating a merged copy.

#target photoshop
var docA = [];
for(var i=0;i<app.documents.length;i++){
    docA.push(app.documents[i]);
    }
activeDocument = docA[0];
newFile ();
var doc = activeDocument;
for(var i=1;i<docA.length;i++){
    var lastX = doc.layers[0].bounds[2];
    var lastY = doc.layers[0].bounds[1];
    var srcD = app.activeDocument = docA[i];
    var curLayer = srcD.activeLayer = srcD.layers[0];
    curLayer.duplicate (doc.layers[0], ElementPlacement.PLACEBEFORE);
    app.activeDocument = doc;
    var docCurlayer = doc.layers[0];
    var moveX = lastX - curLayer.bounds[0];
    var moveY = lastY - curLayer.bounds[1];
    docCurlayer.translate(lastX,lastY); 
    }
reveal ();

function newFile(){
    var idDplc = charIDToTypeID( "Dplc" );
        var desc31 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idDcmn = charIDToTypeID( "Dcmn" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idFrst = charIDToTypeID( "Frst" );
            ref3.putEnumerated( idDcmn, idOrdn, idFrst );
        desc31.putReference( idnull, ref3 );
        var idNm = charIDToTypeID( "Nm  " );
        desc31.putString( idNm, """Merged files""" );
    executeAction( idDplc, desc31, DialogModes.NO );    
    }

function reveal(){
    var idRvlA = charIDToTypeID( "RvlA" );
        var desc35 = new ActionDescriptor();
    executeAction( idRvlA, desc35, DialogModes.NO );    
    }

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
Community Beginner ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

LATEST

wow, beauty Chuck! thks!!

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
Community Expert ,
Jan 20, 2020 Jan 20, 2020

Copy link to clipboard

Copied

Wow! That is truly a thing of beauty Chuck!

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