Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all 27456 articles
Browse latest View live

Re: Photoshop action to break apart a very large image into small square

$
0
0

I believe you will have a hard time developing an action to handle different size documents.  If all your Document have a square aspect ratio 1:1 you may be able to record square  selections that are a percentage of the documents equal with and height brake the image into square tiles layers. and the export layer to files.   If your images have different aspect ratios you would need to use Photoshop scripting to cut up your images and it you want to use a 12" x 12" tiles  the Aspect ratio side need to be some multiple of 12.

 

x12 by y12 that is x feet by y feet. A script can use logic to look at the a document canvas size in pixels and its resolution to see if the a document sides are a multiple of 12".  Actions can not use logic they are hard coded steps.

 

If a document is a correct size a script could easily create the 12" x 12" tile document you need. With file names  like ImageName+Row#+Column#.jpg.


Re: Starting scripts from the command line not working with Win10

$
0
0

I would think that that would be in Microsoft documentation about command line syntax and Adobe may have some Photoshop command line options in their Photoshop Documentation.   Adobe's Photoshop Documentation is not the greatest.  I have been using Photoshop for many years since Photoshop version 3.  I have never found and Adobe documentation on Photoshop command line options or switches.  Most  startup option seem to be Keyboard shortcuts.  If you find and Adobe Documentation one the subject let us.

 

You found your Problem was your  Windows Command line Syntax was wrong.

 

Capture.jpg

Re: Photoshop action to break apart a very large image into small square

$
0
0

Assuming you have all Guides already set-up and have one layer in PSD file.

Script cuts image into small peaces defined by Guides and names them according to their grid number/letter. Rows are named with numbers [0-9] and columns by letters [A-Z]. Each slice is saved as PNG file with original name + grid number&letter.

 

Have one layer in the file. Add bunch of Guides. Save file as PNG and run the script. Enjoy the rest of your day!

 

Use it on your own risk.

 

https://bitbucket.org/snippets/rendertom/6Angy

 

(function() {    try {        #target photoshop        if (app.documents.length === 0)            return alert("Open file first");        var doc = app.activeDocument;        if (doc.layers.length !== 1)            return alert("This script can handle only one layer in file. Merge your layers and run script again.");        var originalRulerUnits = app.preferences.rulerUnits,            plot = plotDocument(),            selectionCoordinates = [],            newLayer, newDocument,            layer = doc.layers[0];        app.preferences.rulerUnits = Units.PIXELS;        app.displayDialogs = DialogModes.NO;        layer.isBackgroundLayer && layer.isBackgroundLayer = false;        layer.selected = true;        doc.selection.deselect();        for (var i = 0, il = plot.length; i < il; i++) {            selectionCoordinates[0] = [plot[i].x, plot[i].y];            selectionCoordinates[1] = [plot[i].x, plot[i].y + plot[i].height];            selectionCoordinates[2] = [plot[i].x + plot[i].width, plot[i].y + plot[i].height];            selectionCoordinates[3] = [plot[i].x + plot[i].width, plot[i].y];            doc.selection.select(selectionCoordinates);            if (selectionHasPixels()) {                newLayer = layerViaCopy();                newLayer.name = plot[i].name;                duplicateToNewDocument(newLayer)                app.activeDocument.trim(TrimType.TRANSPARENT);                savePNG(File(doc.path + "/" + getBaseName(doc) + "-" + plot[i].name + ".psd"));                app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);                app.activeDocument = doc;                newLayer.remove();            }        }        app.preferences.rulerUnits = originalRulerUnits;        alert("done")        /////// HELPER FUNCTIONS ///////        /**        * Converts document Guides information to array of coordinates blocks        * @return {[Array]} [Array of objects, containing x, y, width, height, name properties]        */        function plotDocument() {            var guidesArray = getGuidesCoordinates(),                coords = [],                vStart, vCurrent = vMin = 0,                hStart, hCurrent = hMin = 0,                columnName = "";            if (guidesArray.vertical[0] !== 0)                guidesArray.vertical.unshift(0);            if (guidesArray.vertical[guidesArray.vertical.length - 1] < Number(app.activeDocument.width))                guidesArray.vertical.push(Number(app.activeDocument.width))            if (guidesArray.horizontal[0] !== 0)                guidesArray.horizontal.unshift(0);            if (guidesArray.horizontal[guidesArray.horizontal.length - 1] < Number(app.activeDocument.height))                guidesArray.horizontal.push(Number(app.activeDocument.height))            for (var h = 1, hl = guidesArray.horizontal.length; h < hl; h++) {                hStart = hCurrent;                hCurrent = guidesArray.horizontal[h];                vCurrent = guidesArray.vertical[0];                vMin = guidesArray.vertical[0];                columnName = "a";                for (var v = 1, vl = guidesArray.vertical.length; v < vl; v++) {                    vStart = vCurrent;                    vCurrent = guidesArray.vertical[v];                    coords.push({                        x: vStart,                        y: hStart,                        width: vCurrent - vMin,                        height: hCurrent - hMin,                        name: h + columnName                    });                    vMin = vCurrent;                    columnName = String.fromCharCode(columnName.charCodeAt(0) + 1).toString();                }                hMin = hCurrent;            }            return coords        }        /**        * Creates object with vertical/horizontal arrays that contain Guides coordinates        * @return {[Object]} []        */        function getGuidesCoordinates() {            var docGuides = app.activeDocument.guides,                verticalGuides = [],                horizontalGuides = [];            for (var g = 0, gl = docGuides.length; g < gl; g++) {                if (docGuides[g].coordinate >= 0) {                    if (docGuides[g].direction === Direction.VERTICAL && docGuides[g].coordinate <= Number(app.activeDocument.width)) {                        verticalGuides.push(Number(docGuides[g].coordinate))                    } else if (docGuides[g].direction === Direction.HORIZONTAL && docGuides[g].coordinate <= Number(app.activeDocument.height)) {                        horizontalGuides.push(Number(docGuides[g].coordinate))                    }                }            }            return {                vertical: removeDuplicatesFromArray(verticalGuides).sort(),                horizontal: removeDuplicatesFromArray(horizontalGuides).sort()            }        }        /**        * Removes Dulpicates from array        * @param  {[Array]} userArray [Array with values]        * @return {[Array]}  [New array without duplicates]        */        function removeDuplicatesFromArray(userArray) {            var seen = {},                out = [],                j = 0,                item;            for (var i = 0, il = userArray.length; i < il; i++) {                item = userArray[i];                if (seen[item] !== 1) {                    seen[item] = 1;                    out[j++] = item;                }            }            return out;        }        /**        * Checks if selection has live pixels        * @return {[Bool]} [True if selection contains pixels]        */        function selectionHasPixels() {            try {                app.activeDocument.selection.copy();                return true            } catch (e) {                return null            }        }        /**        * Creates new layer via copy.        * @return {[Object]} [New layer]        */        function layerViaCopy() {            app.activeDocument.selection.copy();                  app.activeDocument.artLayers.add();            app.activeDocument.paste();            return app.activeDocument.activeLayer;        }        /**        * Duplicates selected layer to new document        * @param  {[Object]} layer [Layer to duplicate]        * @return {[Object]}      [Returns layer in new document]        */        function duplicateToNewDocument(layer) {            var doc = app.activeDocument;            var newDocument = app.documents.add(doc.width, doc.height, doc.resolution);            app.activeDocument = doc;            var newLayer = layer.duplicate(newDocument, ElementPlacement.INSIDE);            app.activeDocument = newDocument;            newDocument.layers[newDocument.layers.length - 1].remove();            return newLayer;        }        /**        * Saves active document as PNG file with transparency        * @param  {[Object]} saveFile [File Object with PNG extension]        * @return Nothing        */        function savePNG(saveFile) {            var pngSaveOptions = new PNGSaveOptions();            pngSaveOptions.compression = 9;            pngSaveOptions.interlaced = false;            activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);        };        /**        * Gets document name without extension        * @param  {[Object]} document [Optional. Document to whos name to get]        * @return {[String]}          [Document name without extension]        */        function getBaseName(document) {            document = document || app.activeDocument;            return decodeURI(document.name.substring(0, document.name.lastIndexOf(".")));        }          } catch (e) {        alert(e.toString() + "\nScript File: " + File.decode(e.fileName).replace(/^.*[\|\/]/, '') +            "\nFunction: " + arguments.callee.name +            "\nError on Line: " + e.line.toString())    }
})();

Re: Photoshop action to break apart a very large image into small square

$
0
0

1) Create slice across whole image

2) Calculate desired size in pixels

3) set divide slice like this:

 

2017-04-01_121647.jpg

4) file > export > save for web legacy

 

Should by quite fast. Could be actionable a run in batch.

Doesn't matter number of layers.

Re: Interactive selection using photoshop script

$
0
0

Found this searching and had a chuckle with Adobe staff (maybe that happened later?) asking forums how to do things

Save as jpg, containing selected layer name

$
0
0

Hello, greetings to all!

1- I open a document,

2- I Perform an action to set the color, size, and print type setting

3- I Merge all layers of the document, and rename it to: Print_A4-MD

4- Now I need to create a backup of this configured document for future impressions.

The first 3 steps I can perfectly with actions I recorded:

 

For step 4: I found a form that I like a lot:

When I select the "Print_A4-MD" layer and execute a Script, I save in the same directory a file named Print_A4-MD.jpg, containing the name of the selected layer.

My question is:

How to modify the script to save Print_A4-MD_01.jpg, Print_A4-MD_02.jpg, Print_A4-MD_03.jpg ..... whenever I re-run this script on the same selected layer ?? Thank you.

Here is the script for review:

 

// saves jpg into same folder; 
// be advised: this  overwrites existing jpgs of the same name without prompting. 
// 2010, use it at your own risk; 
#target photoshop; 
if (app.documents.length > 0) { 
var thedoc = app.activeDocument; 
// getting the name and location; 
var docName = thedoc.name; 
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]} 
else {var basename = docName}; 
// getting the location, if unsaved save to desktop; 
try {var docPath = thedoc.path} 
catch (e) {var docPath = "~/Desktop"}; 
// jpg options; 
var jpegOptions = new JPEGSaveOptions(); 
jpegOptions.quality = 9; 
jpegOptions.embedColorProfile = true; 
jpegOptions.matte = MatteType.NONE; 
//save jpg as a copy: 
thedoc.saveAs((new File(docPath+'/'+thedoc.activeLayer.name+'.jpg')),jpegOptions,true); 
//that’s it; thanks to xbytor; 
}; 

Re: Save as jpg, containing selected layer name

$
0
0

There you go.

(function() {    try {        #target photoshop;        if (app.documents.length > 0) {            var thedoc = app.activeDocument;                      // getting the name and location;              var docName = thedoc.name;            var basename = docName;            if (docName.indexOf(".") != -1)                basename = docName.match(/(.*)\.[^\.]+$/)[1]            // getting the location, if unsaved save to desktop;            var docPath = "~/Desktop";            try {                docPath = thedoc.path;            } catch (e) {}                      // jpg options;              var jpegOptions = new JPEGSaveOptions();            jpegOptions.quality = 9;            jpegOptions.embedColorProfile = true;            jpegOptions.matte = MatteType.NONE;                      //save jpg as a copy:            var saveFile = docPath + '/' + thedoc.activeLayer.name + '.jpg';            if (File(saveFile).exists)                saveFile = incrementFile(saveFile);                      thedoc.saveAs(new File(saveFile), jpegOptions, true);            //that’s it; thanks to xbytor;          };        function incrementFile(pathToFile) {            var saveSufixLength = 2,                suffix = zeroPad(0, saveSufixLength),                newPathToFile = pathToFile,                suffixInteger, folder, fileName, extension;            while (File(newPathToFile).exists) {                suffixInteger = parseInt(suffix, 10);                suffixInteger += 1;                suffix = zeroPad(suffixInteger, saveSufixLength);                folder = File(pathToFile).path;                fileName = File(pathToFile).name.substring(0, File(pathToFile).name.lastIndexOf("."));                extension = File(pathToFile).name.substring(File(pathToFile).name.lastIndexOf(".") + 1, File(pathToFile).name.length);                newPathToFile = folder + "/" + fileName + "_" + suffix + "." + extension;            }            return newPathToFile;            function zeroPad(num, digit) {                var tmp = num.toString();                while (tmp.length < digit) {                    tmp = "0" + tmp;                }                return tmp;            }        }    } catch (e) {        alert(e.toString() + "\nScript File: " + File.decode(e.fileName).replace(/^.*[\|\/]/, '') +            "\nFunction: " + arguments.callee.name +            "\nError on Line: " + e.line.toString())    }
})();

Re: Save as jpg, containing selected layer name

$
0
0

It worked perfect! Forever grateful to you. I see almost all posts in this forum and I realize that you "Tomas Sinkunas" has collaborated very efficiently and helped a lot. Many thanks for the great help and congratulations for the work on After Efects.

www.rendertom.com


Re: Get timecode data using AM code

$
0
0

Thanks for the reply. I downloaded and checked it out but it's way to confusing for me to figure out.

 

All I wanted to do was get the current Hours, Minutes, Seconds and Frame from he timeline into 4 variables. I couldn't figure out how to do that with the code in the download. Anyway, I think I'm just giving up on that now and moving on to something else. I really wish that Adobe would update the DOM and the documentation for it. Piecing together cryptic code to attempt to do simple things is too complex for a simple minded script writer such as myself.

Re: Save as jpg, containing selected layer name

Re: Get timecode data using AM code

$
0
0

Thing you downloaded can convert action manager code into "DOM like" format.

 

The problem is that you need to get action descriptor and this you can get through the action manager code.

Anyway there will be much less AM code and basic descriptors e.g. document or current layer usually contains everything you need and usually looks same or similar.

 

Anyway scripting in Photoshop can be hardcore if you are not lucky.

Get AppleScript to Show up in File Menu

$
0
0

Apparently it used the be the case that an AppleScript (.scpt) could be dropped in the Photoshop Scripts folder, and it would show up in the File menu in Ps. Does this no longer work?

 

Is there any way to bind an AppleScript to a Photoshop hotkey?

Re: Call a new HTML panel of the HTML panel

$
0
0

thank you very much, and you could provide a code example ?

Re: Photoshop action to break apart a very large image into small square

$
0
0

Thanks Jarda BerezaI have chekced your script this will make very squire 12x12in but not show numbers also show file name as started with Capture 1a etc...

Re: CS5 - Error 22:Window does not have a constructor

$
0
0

It hasn't helped me. same error message and this:

Line: 388

->   var w = new Window(res);


Re: Call a new HTML panel of the HTML panel

$
0
0

Lest suppose You have 2 HTML panels 'myPanel1' & 'myPanlel2'

 

They are defined in the CSXS/manifiest.xml like:

<Extension Id="myPanel1">
...<Extension Id="myPanel2">


You have loaded CSInterface-6.1.0.js into Your panels via

<script src="./lib/CSInterface-6.1.0.js"></script>

( Version number may vary )

 

 

var csInterface = new CSInterface();

is amongst the first lines of Your panels javascript code.

 

You just need to call

csInterface.requestOpenExtension( 'myPanel2' );

 

from myPanel1.

How do i view all messages in scripting forum?

$
0
0

Hi, when I view the scripting forum, there are a few topics, and then a "More" button. When I click it, it loads another 6 or so messages, for a total of 12 topics to be viewed. But I can't find any link to go to page 2, page 3, page 4, etc.

 

How do I keep viewing all the topics in this section?

Re: How do i view all messages in scripting forum?

$
0
0

Just click on the numbers for the next pages.

Re: EPS files keep interrupting batch process? asks to Save As... asks to rasterize image.

$
0
0

Thanks a lot!

You solved my problem!

 

If anybody else will read this thread in the future, this is why the window kept appearing:

 

My initial saveOptions (window appears):

var saveOptions = new EPSSaveOptions();

saveOptions.embedColorProfile = true;

saveOptions.encoding = SaveEncoding.JPEGMAXIMUM;

saveOptions.halftoneScreen = true;

saveOptions.interpolation = true;

saveOptions.preview = Preview.EIGHTBITTIFF;

saveOptions.psColorManagement = true;

saveOptions.transferFunction = true;

saveOptions.transparentWhites = true;

saveOptions.vectorData = true;

aktDoc.flatten();

aktDoc.saveAs(new File(whereToSave), saveOptions, false);

 

My "new" saveOptions (window does not appear anymore):

var saveOptions = new EPSSaveOptions( );

saveOptions.embedColorProfile = true;

saveOptions.BINARY;

saveOptions.halftoneScreen = true;

saveOptions.interpolation = true;

saveOptions.psColorManagement = true;

saveOptions.transferFunction = true;

saveOptions.vectorData = true;

aktDoc.saveAs(new File(whereToSave), saveOptions, true);

 

I found out that the window does not appear anymore after I removed the option "transparentWhites".

 

Thanks again!

How to get the maximum value of the image RGB

$
0
0

Hi Everyone!

 

Is this possible to get the maximum value of the image RGB? on selected layer.

 

I tried getting value from channel histogram but didn't get it. Please

 

Please, anyone help me out this problem.

 

Regards,

 

-yajiv

Viewing all 27456 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>