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

How to insert a logo.png in the center of the document

Contributor ,
Sep 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

Continuing my series of studies on ScriptUI.

How to insert a logo.png in the center of the document through a "Select Folder" button, so that the path of that folder is registered in the user interface (ScriptUI).

Same as the image below:

Screenshot_1.jpg

Thank you!

TOPICS
Actions and scripting

Views

1.5K

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 , Sep 23, 2017 Sep 23, 2017

#target photoshop

var myFile = new File('c/')

var mask = '*.png'

var doc = activeDocument;

var dlg = new Window('dialog','Add a logo to the image');

    dlg.alignChildren = ['top','left'];

    dlg.btnGp = dlg.add('group');

        dlg.btnGp.logoCk = dlg.btnGp.add('checkbox',undefined,'Add a logo');

        dlg.btnGp.logoBtn = dlg.btnGp.add('button',undefined,'Select a file');

        dlg.btnGp.logoPath = dlg.btnGp.add('statictext',undefined,'');

        dlg.btnGp.logoPath.size = [400,15];

            dlg.b

...

Votes

Translate

Translate
Adobe
Community Expert ,
Sep 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

Are you talking about just getting a folder of files that you can then insert the png,  or are you talking about getting the path for the png to insert into files?

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
Contributor ,
Sep 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

Hi Chuck Uebele how are you buddy!

  I'm planning a dialog box with buttons and checkbox, the purpose I want, would add a button called "select folder" to locate and insert a file.png inside document whenever the checkbox called "Add Logo" is enabled then the "Select Folder" button would be active and when I clicked this button, I would look for the file.png file in some folder so that the path is registered in the dialog giving a more professional look to the project.

Screenshot_0000.png

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 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

#target photoshop

var myFile = new File('c/')

var mask = '*.png'

var doc = activeDocument;

var dlg = new Window('dialog','Add a logo to the image');

    dlg.alignChildren = ['top','left'];

    dlg.btnGp = dlg.add('group');

        dlg.btnGp.logoCk = dlg.btnGp.add('checkbox',undefined,'Add a logo');

        dlg.btnGp.logoBtn = dlg.btnGp.add('button',undefined,'Select a file');

        dlg.btnGp.logoPath = dlg.btnGp.add('statictext',undefined,'');

        dlg.btnGp.logoPath.size = [400,15];

            dlg.btnGp.logoBtn.enabled = false;

            dlg.btnGp.logoPath.enabled = false;

           

        dlg.ok = dlg.add('button',undefined,'Okay');

           

            dlg.btnGp.logoCk.onClick = function (){

                if(this.value){

                    dlg.btnGp.logoBtn.enabled = dlg.btnGp.logoPath.enabled = true;

                    }

                else{

                    dlg.btnGp.logoBtn.enabled = dlg.btnGp.logoPath.enabled = false;

                    }

                }

       

            dlg.btnGp.logoBtn.onClick = function(){

                myFile = File.openDialog ('Select a sogo file', mask, false);

                if(myFile !=null){dlg.btnGp.logoPath.text = myFile.fsName};

                };

           

            dlg.ok.onClick = function(){

                try{

                if(dlg.btnGp.logoCk.value&&myFile.exists){

                    placeFile (myFile)

                    raster ();

                    }

                }

                catch(e){} 

                dlg.close();

                }

       

        dlg.show();

       

function placeFile(file){

    var idPlc = charIDToTypeID( "Plc " );

        var desc9 = new ActionDescriptor();

        var idIdnt = charIDToTypeID( "Idnt" );

        desc9.putInteger( idIdnt, 3 );

        var idnull = charIDToTypeID( "null" );

        desc9.putPath( idnull, new File( file ) );

        var idFTcs = charIDToTypeID( "FTcs" );

        var idQCSt = charIDToTypeID( "QCSt" );

        var idQcsa = charIDToTypeID( "Qcsa" );

        desc9.putEnumerated( idFTcs, idQCSt, idQcsa );

        var idOfst = charIDToTypeID( "Ofst" );

            var desc10 = new ActionDescriptor();

            var idHrzn = charIDToTypeID( "Hrzn" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc10.putUnitDouble( idHrzn, idRlt, 0.000000 );

            var idVrtc = charIDToTypeID( "Vrtc" );

            var idRlt = charIDToTypeID( "#Rlt" );

            desc10.putUnitDouble( idVrtc, idRlt, 0.000000 );

        var idOfst = charIDToTypeID( "Ofst" );

        desc9.putObject( idOfst, idOfst, desc10 );

    executeAction( idPlc, desc9, DialogModes.NO );

    }

   

function raster(){

    var idrasterizeLayer = stringIDToTypeID( "rasterizeLayer" );

        var desc12 = new ActionDescriptor();

        var idnull = charIDToTypeID( "null" );

            var ref1 = new ActionReference();

            var idLyr = charIDToTypeID( "Lyr " );

            var idOrdn = charIDToTypeID( "Ordn" );

            var idTrgt = charIDToTypeID( "Trgt" );

            ref1.putEnumerated( idLyr, idOrdn, idTrgt );

        desc12.putReference( idnull, ref1 );

    executeAction( idrasterizeLayer, desc12, 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
Contributor ,
Sep 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

Perfect Chuck Uebele as always, you did a great job. Just one more curiosity. Would it be possible for the directory (folder path) of the last inserted image to be registered so that whenever I open the dialog? It would be something similar to the script "Image Processor ..." Thank you very much for sharing your knowledge.

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 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

That could be added and so could logo resizing relative to image size be added.  Scripting is powerful. But you need to be able to code in javascript or VBS or Applescript.

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 ,
Sep 24, 2017 Sep 24, 2017

Copy link to clipboard

Copied

If you want to use the same logo, just hard code the path in line 2 of my above example.

var myFile = new File('/c/logo.png')

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
Contributor ,
Sep 24, 2017 Sep 24, 2017

Copy link to clipboard

Copied

LATEST

Perfect!Chuck Uebele Thank you very much for your time and help. JJMack Thank you for your alternatives, they are very useful.

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 23, 2017 Sep 23, 2017

Copy link to clipboard

Copied

If you know the png logo file and you know the size you want it to be relatve to an image's size and  you want it centered  you do not need the script to have a ScriptUI dialog and that script can be batched.

If you want to be able to select at png logo, specify the relative size the logo should be and be able to choose where the logo should be placed on the image then  the script needs to have a ScriptUI dialog.

If you want to be able to batch that script.  The script may be programmed as a Photoshop plug-in so you can record using the plug-in script in an action. The plug-in script will record the settings you used in its dialog recording the action into the action step. When the action is played the plug-in script will bypass displaying its dialog and use the recorded settings passed by the actions script step.

A script could also be programmed as a batch process  and not need to include Plug-in support. Where you select which image files that should have the logo added in the script User Interface..

The script posted above woud not wok will IMO with different size image and different size logo png files.

Capture.jpg

Here is a script I posted several time to places a logo on the bottom of images.  It has no dialog you you customize it by editing the first few variable statements. it handle size well. Images and logos can be any reasonable size.  Logo PNG file should be created large for downsizing works better then up sizing.

http://www.mouseprints.net/old/dpr/PlaceWatermark.jsx

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 ,
Sep 24, 2017 Sep 24, 2017

Copy link to clipboard

Copied

Ps-Design

I see you have 0 points so your most likely  relatively new to these forums however you record shows you are interested in Photoshop Scripting which means you not normal.  Most Photoshop never write a Photoshop Script.  Let me introduce myself.   I hack some at Photoshop scripting.  Scripting is quite hard for me for I do not know JavaScript and I can not type so I'm always in error correction mode. You will see typing errors and spelling errors in all my appends and most may be hard to read.   So why do I do it?   I'm trying to keep the gray matter between my ears functioning.   It the best and most powerful tool I have when using Photoshop.   And I do know something about Photoshop and feel I can actually help others.

Hopefully  from  my append here you now realize the are basically three types of Scripts.  Ones without Dialogs,  Ones that have a dialog and are always interactive.  And ones that have a dialog that are Photoshop Plug-in that they can be used interactively or fully automated without displaying a dialog.

I often will first prototype most of what I want in a script in an action where I will throw in some interactive steps where I will need to use scripting logic.  Action can also use scripts and I have written some simple scripts for use in actions so actions can do thing normally actions can not.

You ask about scripting Photoshop to place a logo centered on an image with some dialog.  But I did not post one or did I?

A little gray matter use.  If I use the PlaceWatermak.jsx JJMack posted in an action what can I do?

Step 1 menu file>scripts>PlaeceWatermark

Step 2 Select All

Step 3 menu layer>align layers to selection Horizontal center

Step 4 menu layer>align layers to selection Vertical center

what else can I do

Step 5 Add layer style

Step 6 Save As jpg

But that action has no dialog how can I doe tahe with ans Action

Menu File>Automate>Batch

in dialog select input image folder

select place watermark action

check override save as

select destination folder

Yes I'm a hacker....  Welcome   PS-Design

Ps you could leave out the save as and use the action with Image Processor script or Image Processor Pro Plug-in  script....

They also have dialogs can save more then jpeg image files and can also resize image to fit the size you want...

Happy Hacking....

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