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

Creating a tinyPNG script for an already opened file

Engaged ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

Hello everyone,

I wanted to compress files and came across tinyPNG that compresses PNG and JPG files.

I want to use it on an already opened file in Photoshop. i also want to use script.

I found on their website they shared a script to use tinyPNG on opened files:

I want to combine it with a script I have to save JPG quality 5.

i will ask their support as well, if they shared their script maybe they'll know.

thanks in advance for any help.

TOPICS
Actions and scripting

Views

2.6K

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
Adobe
Advocate ,
Jun 22, 2018 Jun 22, 2018

Copy link to clipboard

Copied

This does not work on open files

compresses the files contained in a folder

but to do this you have to buy the tinypng plugin first.

however, it's up to you what you really need

What should the script do?

What are the steps you want to do?

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
Engaged ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

1. i have the plugin already in my Photoshop.

2. I have a NEF file, i save it as PSD + JPG (Quality = 5) + another JPG (Quality = 5) after hiding the watermark

3. I want the 2 JPG files i saved to be compressed by tinyPNG, i think that i don't even need a JPG file in the first place to compress and i can save a JPG from a PSD file. that is written on their website:

so to sum up i need PSD + 2 compressed/saved JPG by tinyPNG

here is the script i'm using for step 2 i mentioned:

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 ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

What are you actually trying to do. NEF  files are RAW Nikon camera  files and need to be converted into a RGB image wit a converter like ACR which can open the rgb image in Photoshop as a Smart Object layer or a Background layer.  These can be saved into image files like PSD, Jpeg, PNG etc.   IMO you should download and install Image Processor Pro and use that to save the files you want saved.  I do not understand the need for a small PNG file there is no transparency in a Converted NEF image.

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
Engaged ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

tinyPNG is the name of the website.

a third party program/plugin that compresses/creates smaller files for both JPG and PNG. I need JPG.

I save the NEF as PSD. it is indeed RGB. 8 bits/channel. everything is normal.

I want to have smaller JPGs using this. and i want to do it on my already opened psd files in Photoshop. and save the JPG to the same location as the PSD. I want also to save another JPG but this time with a suffix "clean" meaning no watermark.

(i have a script that does the last thing):

so that's what i have already:

- I have their plugin installed. (it is used for their script and also for saving an already opened file BUT to a pre-determined folder and not to the same folder like I want)

- I have a script of them that you need to choose a folder and then compress it.

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
People's Champ ,
Jun 23, 2018 Jun 23, 2018

Copy link to clipboard

Copied

Try this

var f = new Folder("C:\\TEST"); // your folder

// save png

export_tiny_png(f);

   

// save jpeg

export_tiny_png(f, false);

alert("Done!");

function export_tiny_png(folder, png, scale)

    {

    try {

        if (png == undefined) png = true;

        if (scale == undefined) scale = 100;

        var d1 = new ActionDescriptor();

        d1.putPath(stringIDToTypeID("in"), folder);

        d1.putUnitDouble(stringIDToTypeID("scale"), stringIDToTypeID("percentUnit"), scale);

        d1.putEnumerated(stringIDToTypeID("fileType"), charIDToTypeID("tyFT"), charIDToTypeID(png?"tyPN":"tyJP"));

        var d = new ActionDescriptor();

        d.putObject(stringIDToTypeID("using"), charIDToTypeID("tinY"), d1);

        executeAction(stringIDToTypeID("export"), d, DialogModes.NO);

        }

    catch (e) { throw(e); }

    }

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
Engaged ,
Jun 24, 2018 Jun 24, 2018

Copy link to clipboard

Copied

unfortunately photoshop crushes

i'll try to really simplify what i need to make it easier.

i have a psd file on D:\carpet\

the file name is file

I have it open on photoshop

i have the tinyPNG plugin that saves both PNG and JPG (i will probably need 2 different scripts, one for PNG, one for JPG, and JPG by default is more important.

i have tinyPNG plugin in photoshop:

but it doesn't save to the same place as the file location (which is D:\carpet\),it saves to the location i put the last time on the plugin.

i need to save to the same location, because the sometimes i will have files from different folders.

that's all.

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
People's Champ ,
Jun 24, 2018 Jun 24, 2018

Copy link to clipboard

Copied

LATEST

Everything is working.
I tested it on version 2.3.9 and on CC2018 x86. Photoshop crashes if the save folder does not exist or not enough rights to write to the folder.
You must replace the path "C / TEST" in the script with your own, and the folder must exist. With the script, both jpg and png are suggested.

You must modify the script yourself as you need.

PS. If you replace DialogModes.NO with DialogModes.ALL, you will see the appearance of the plugin window with the parameters already set by you.

UPD.

If you want to save to the folder with the original file, then you need to use instead of the save folder app.activeDocument.path



var f = app.activeDocument.path;

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