• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Script or action to import files as pixel layers

Community Beginner ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

Hi All,

Would anyone here have an idea how to batch import a file as a pixel layer in a bunch of other files? I've tried an action with the "embed" command, but it imports as smart object and resizes to fit in the destination file....

I would like to import as a regular pixel layer, (or if it's a smart object, impose that it stays at 100% and not be resized to fit the destination).

 

open to ideas.... thanks,

Jonathan

 

TOPICS
Actions and scripting

Views

1.1K

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 2 Correct answers

Community Expert , Sep 13, 2021 Sep 13, 2021

Though you wrote Import import does not seem to have a option to import Image files.  Menu "File>Script>Loads Files into a stack" seems to be able to import File into a  stack of image layers they are not smart object layers.  Where menu "File>Place Embedded|Linked" can import images files as smart object layers.  It  has been reported to that "Place" may scale smart object.   Place will scale the object's image if the placed in image file has a different print resolution as the current document

...

Votes

Translate

Translate
Community Beginner , Sep 13, 2021 Sep 13, 2021

Thanks for this long thoughtfull help, JJMACK.

I concentrated on your remark that copy/paste doesn't resize, and doesn't paste as smart object, and so I ended up with an action that opens, copies, closes, then pastes (in place) the wanted layer. This is a good, simple enough solotion for my problem  šŸ™‚

Again, thanks for the help.

J

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied


if it's a smart object, impose that it stays at 100%

Are you sure? Resolution matters with Smart Objects and if the receiving document and the placed document do not have the same resolution a Smart Object at 100% may still have been scaled. 

 

Have you checked out File > Scripts > Load Files into Stack? 

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 ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

Thanks, but stack doesn't do it, since the idea is to automate and add 1 single layer into many files.
Sure about the scaling: its a texture to be applied, and if scaled the rendering effect is not the same...
What I'm looking for is basically done manually by sliding one layer between two open documents, but somehow this appearingly simple task is not that simple to script...

 

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 ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

Though you wrote Import import does not seem to have a option to import Image files.  Menu "File>Script>Loads Files into a stack" seems to be able to import File into a  stack of image layers they are not smart object layers.  Where menu "File>Place Embedded|Linked" can import images files as smart object layers.  It  has been reported to that "Place" may scale smart object.   Place will scale the object's image if the placed in image file has a different print resolution as the current document current resolution.   Place may also scale the  object's image if you have "Resize Image During Place" checked in your Photoshop preferences and the smart object doe not fit one the current document canvas.   If used interactivity through Photoshop UI "Place may also have a Interactive transform to scale the image that you can accept or change.     With a Script you can insure the Place will not Scale the object's Image be changing the current resolution of the document the to print  resolution of the file you will be placing in and you set your preferences not the "Scale during Place" or after you Place in the file you resize the layer to 100%. Then you can change the document resolution beck to what is was before you changed it to match the placed in files print resolution.

 

 

You could Open the Files in your script snd copy mergs  it into the clipboard close the opened document and then paste the images into the current document.  Copy paste. Duplicate Layer and Draging and droping does not scale images.   Place may scale an object's images.....

Capture.jpg

 

// June 2019  John J. McAssey (JJMack) 
// This attempt to add an Additional Photoshop Place Embedded No Degrade feature under menu file scripts listed under Image Processor
// File>Scripts>placeImageNoDegradeInteractive... Embedded Image without a Degrading Resizing based on file print DPI setting.
// The Photoshop Preferences Resize During Place if set will scale large object to be scaled to fit on canvas then an
// Interactive transform enable you to adjust the Smart Object layers associated transform for the document composite use.
// This Script supports PSD, Tiff, Jpeg, PNG and Camera Raw file placement.  However, Camera RAW files have no print DPI 
// for they are not printable.  This script assumes your default Camera RAW work-flow conversion is to a 300DPI resolution
// The following Image Filetype are not supported for Photoshop support is not what it should be IMO or the file poor or to large to embed
// or are not commonly used by me.: PSB SVG AI BMP GIF EPS PDF DCS DICOM  IFF Jpeg2000 PCX PDF Pixar PBM Targa   etc...
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.
/* Help 
<javascriptresource>
<name>$$$/JavaScripts/placeImageNoDegradeInteractive/Menu=placeImageNoDegradeInteractive...</name>
<about>JJMack's placeImageNoDegradeInteractive  Copyright 2019 Mouseprints  Place without degrading image quality with an Interactive Transform</about>
<category>aaaThisPutsMeAtTheTopOfTheMenu</category>
<enableinfo>true</enableinfo>
</javascriptresource>
*/
if (!documents.length) alert('There are no documents open.', 'No Document');
else {
	if (!CheckVersion(13)) { alert("Photoshop version CS6+ is required.")}
	else {
		var imageFile;
		imageFile = selectFile ();
		if (imageFile==null) alert("No Image Files Selected", 'Cancelled');
		else if (!imageFile.name.match(/\.(crw|nef|raf|orf|mrw|dcr|mos|raw|pef|srf|dng|x3f|cr3|cr2|erf|sr2|kdc|mfw|arw|nrw|rw2|rwl|iiq|3fr|fff|srw|gpr|dxo|heic|arq|cr3|psd|psb|jpg|jpe|jpeg|png)$/i) ) alert(imageFile.name, 'Not a Supported Image Filetype');
		else placeImageNoDegradeInteractive(imageFile);
	}
}
//////////////////////////////////////////////////////////////////////////////////
//		                    	Helper Functions	            				//
//////////////////////////////////////////////////////////////////////////////////
function CheckVersion(PSV) {
	var numberArray = version.split(".");
	if ( numberArray[0] < PSV ) { return false; 	}
	return true;
}
function selectFile (multi) {   
	if (multi == true) {var theString = "please select Image files"}   
	else {var theString = "please select one image file"};   
	if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.crw;*.nef;*.raf;*.orf;*.mrw;*.dcr;*.mos;*.raw;*.pef;*.srf;*.dng;*.x3f;*.CR3;*.cr2;*.erf;*.sr2;*.kdc;*.mfw;*.arw;*.nrw;*.rw2;*.rwl;iiq;*.3fr;*.fff;*.srw;*.gpr;*.dxo;*.heic;*.arq;*.cr3;*.psd;*.psb;*.tif;*.tiff;*.jpg;*.jpe;*.jpeg;*.png', multi)}   
	else {var theFiles = File.openDialog (theString, getFiles, multi)};  ////// filter files  for mac //////    
	function getFiles (theFile) {   
		if (theFile.name.match(/\.(crw|nef|raf|orf|mrw|dcr|mos|raw|pef|srf|dng|x3f|cr3|cr2|erf|sr2|kdc|mfw|arw|nrw|rw2|rwl|iiq|3fr|fff|srw|gpr|dxo|heic|arq|cr3|psd|psb|tif|tiff|jpg|jpe|jpeg|png)$/i) || theFile.constructor.name == "Folder") return true;   
	};   
	return theFiles   
};	

function placeImageNoDegradeInteractive(file) {
	var	orig_resolution = app.activeDocument.resolution;	// Get document Resolution (Read only change via image resize)
	var orig_ruler_units = app.preferences.rulerUnits;		// Save Units
	app.preferences.rulerUnits = Units.PIXELS;				// Set the ruler units to PIXELS
	// Thanks to SuperMerlin gets image Files Print resolution
	if (file.name.match(/\.(crw|nef|raf|orf|mrw|dcr|mos|raw|pef|srf|dng|x3f|cr3|cr2|erf|sr2|kdc|mfw|arw|nrw|rw2|rwl|iiq|3fr|fff|srw|gpr|dxo|heic|arq|cr3)$/i)) printDPI= 300; 
	else {
		if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');  
		var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ );  
		var xmp = xmpf.getXMP();  
		if(xmp.doesPropertyExist(XMPConst.NS_TIFF, "XResolution")){  
			var res = xmp.getProperty(XMPConst.NS_TIFF, "XResolution");  
			res = res.toString().split("/");  
			printDPI= res[0]/res[1]	
		}
		else printDPI= 72;
	}
	
	if(orig_resolution!=printDPI) app.activeDocument.resizeImage(null, null, printDPI, ResampleMethod.NONE);
	// Place in the file
	var idPlc = charIDToTypeID( "Plc " );
	    var desc5 = new ActionDescriptor();
	    var idnull = charIDToTypeID( "null" );
	    desc5.putPath( idnull, new File( file ) );
	    var idFTcs = charIDToTypeID( "FTcs" );
	    var idQCSt = charIDToTypeID( "QCSt" );
	    var idQcsa = charIDToTypeID( "Qcsa" );
	    desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
	    var idOfst = charIDToTypeID( "Ofst" );
	        var desc6 = new ActionDescriptor();
	        var idHrzn = charIDToTypeID( "Hrzn" );
	        var idPxl = charIDToTypeID( "#Pxl" );
	        desc6.putUnitDouble( idHrzn, idPxl, 0.000000 );
	        var idVrtc = charIDToTypeID( "Vrtc" );
	        var idPxl = charIDToTypeID( "#Pxl" );
	        desc6.putUnitDouble( idVrtc, idPxl, 0.000000 );
	    var idOfst = charIDToTypeID( "Ofst" );
	    desc5.putObject( idOfst, idOfst, desc6 );
	executeAction( idPlc, desc5, DialogModes.NO );
	try { app.runMenuItem(charIDToTypeID(("FrTr"))); }			// Free Transform
	catch(e) {};
	if(orig_resolution!=printDPI) app.activeDocument.resizeImage(null, null, orig_resolution, ResampleMethod.NONE);
	app.preferences.rulerUnits = orig_ruler_units;				// Reset units to original settings
	return app.activeDocument.activeLayer;
}	

 

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 Beginner ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

Thanks for this long thoughtfull help, JJMACK.

I concentrated on your remark that copy/paste doesn't resize, and doesn't paste as smart object, and so I ended up with an action that opens, copies, closes, then pastes (in place) the wanted layer. This is a good, simple enough solotion for my problem  šŸ™‚

Again, thanks for the help.

J

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