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

Duplicate and fit

Advocate ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

I have this need

I would duplicate the document in use

Resize to 1920px

Return the document to the original

And adapt it to the original document size

Without having too much loss of quality.

TOPICS
Actions and scripting

Views

2.9K

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

Engaged , Aug 22, 2017 Aug 22, 2017

Hi

Now, Try this code..

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS

cTID = function(s) {return app.charIDToTypeID(s);};

sTID = function(s) {return app.stringIDToTypeID(s);};

if(documents.length>0) main();

function  main(){

    var docRef = app.activeDocument;  

    var docname=activeDocument.name;

    var ImgW=docRef.width.value

    var ImgH=docRef.height.value  

    va

...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Could you please illustrate with screenshots?

To me it seems you want to resize an image and then resize it to the original size again – what good would that be?

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
Advocate ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

I hope you understand

Duplicate image

Schermata 2017-08-22 alle 11.20.04.png

After duplicate image

Resize to 1024px

Schermata 2017-08-22 alle 11.21.10.png

Once resized to bring on original

Schermata 2017-08-22 alle 11.21.46.png

Fit to image without losing too much quality

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

What do you mean by

Fit to image without losing too much quality

?

Do you want to upscale the downsampled copy?

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
Advocate ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

I would like to adapt it this way

Sorry if I do not speak English well and my tongue

1111.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
Engaged ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Hi

Try this code...

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS

cTID = function(s) {return app.charIDToTypeID(s);};

sTID = function(s) {return app.stringIDToTypeID(s);};

if(documents.length>0) main();

function  main(){

    var docRef = app.activeDocument;  

    var docname=activeDocument.name;

    var theCopy = docRef.duplicate("Dup",true);

    app.activeDocument=theCopy;

    c_Res=theCopy.resolution;

    if(theCopy.height.value>theCopy.width.value){ theCopy.resizeImage(undefined,new UnitValue(1024,'Px'),c_Res, ResampleMethod.AUTOMATIC);}

    else{theCopy.resizeImage(new UnitValue(1024,'Px'), undefined, c_Res, ResampleMethod.AUTOMATIC);}    

    var theLayer=theCopy.backgroundLayer.duplicate(); 

    theLayer.duplicate (docRef, ElementPlacement.PLACEATBEGINNING);

    theCopy.close(SaveOptions.DONOTSAVECHANGES);

    app.activeDocument=docRef;

    docRef.selection.selectAll();

    align('AdCV');

    align('AdCH');

    docRef.selection.deselect();

}

// Align Layer

function align(method) { 

  var desc = new ActionDescriptor(); 

  var ref = new ActionReference(); 

  ref.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) ); 

  desc.putReference( cTID( "null" ), ref ); 

  desc.putEnumerated( cTID( "Usng" ), cTID( "ADSt" ), cTID( method ) ); 

  try{ 

  executeAction( cTID( "Algn" ), desc, DialogModes.NO ); 

  }catch(e){} 

- yajiv

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
Advocate ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Natrev is on the right track

Now I want to fit the original picture

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Now I want to fit the original picture

Again: What do you mean?

If you posted meaningful screenshots you could save some typing …

The task (or what you have revealed of it so far) seems close to nonsensical to me – what is the purpose of the operation?

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Hi

Now, Try this code..

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS

cTID = function(s) {return app.charIDToTypeID(s);};

sTID = function(s) {return app.stringIDToTypeID(s);};

if(documents.length>0) main();

function  main(){

    var docRef = app.activeDocument;  

    var docname=activeDocument.name;

    var ImgW=docRef.width.value

    var ImgH=docRef.height.value  

    var theCopy = docRef.duplicate("Dup",true);

    app.activeDocument=theCopy;

    c_Res=theCopy.resolution;  

    if(theCopy.height.value>theCopy.width.value){ theCopy.resizeImage(undefined,new UnitValue(1024,'Px'),c_Res, ResampleMethod.AUTOMATIC);}

    else{theCopy.resizeImage(new UnitValue(1024,'Px'), undefined, c_Res, ResampleMethod.AUTOMATIC);}    

    var theLayer=theCopy.backgroundLayer.duplicate(); 

    theLayer.duplicate (docRef, ElementPlacement.PLACEATBEGINNING);

    theCopy.close(SaveOptions.DONOTSAVECHANGES);

    app.activeDocument=docRef;

    docRef.selection.selectAll();

    align('AdCV');

    align('AdCH');

    docRef.selection.deselect();

    var theLayer=docRef.activeLayer;   

    var LB = theLayer.bounds;

    var lWidth = LB[2].value - LB[0].value;

    var lHeight = LB[3].value - LB[1].value; 

    if(lWidth>lHeight){

        x=(ImgW/lWidth)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    } 

    else{

        var x=(ImgH/lHeight)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    }   

}

// Align Layer

function align(method) { 

  var desc = new ActionDescriptor(); 

  var ref = new ActionReference(); 

  ref.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) ); 

  desc.putReference( cTID( "null" ), ref ); 

  desc.putEnumerated( cTID( "Usng" ), cTID( "ADSt" ), cTID( method ) ); 

  try{ 

  executeAction( cTID( "Algn" ), desc, DialogModes.NO ); 

  }catch(e){} 

-yajiv

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

It’s nice of you to write the code but what do you think the use/benefit/aim of the procedure is?

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Hi Chris,

I understood what is your saying. However what I understood, the Image size going to be reduced with same pixel dimension. That's the reason I written code.

-yajiv

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

But would certain Filters not achieve a very similar result (with regard to damage and savings)?

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Hi

Try this code also..

var strtRulerUnits = app.preferences.rulerUnits; 

var strtTypeUnits = app.preferences.typeUnits; 

app.preferences.rulerUnits = Units.PIXELS; 

app.preferences.typeUnits = TypeUnits.PIXELS 

 

if(documents.length>0) main(); 

function  main(){ 

    var docRef = app.activeDocument;    

    var ImgW=docRef.width.value

    var ImgH=docRef.height.value 

    var docname=activeDocument.name; 

    docRef.flatten();

    c_Res=docRef.resolution; 

    var theLayer=docRef.backgroundLayer.duplicate();

    var LB = theLayer.bounds;

    var lWidth = LB[2].value - LB[0].value;

    var lHeight = LB[3].value - LB[1].value; 

    if(lWidth>lHeight){

        x=(1024/lWidth)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    } 

    else{

        var x=(1024/lHeight)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    }   

    var theLayer=docRef.layers[0];   

    docRef.activeLayer=theLayer;

    if(lWidth>lHeight){       

        x=(ImgW/1024)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    } 

    else{

        var x=(ImgH/1024)*100;

        theLayer.resize(x,x,AnchorPosition.MIDDLECENTER);

    }   

-yajiv

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
Advocate ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

natrev

Your scripts are fine

But there is a misunderstanding

It should not duplicate the image

But must duplicate the document

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

Copy link to clipboard

Copied

Have no Idea of what you would the want to mask in duplicated document resized 1920

#target photoshop; 

app.bringToFront(); 

if (documents.length)  app.activeDocument.suspendHistory('ResizDupe1920','main()');

///////////////////////////////////////////////////////////////////////////////

//                            main function                                  //

///////////////////////////////////////////////////////////////////////////////

function main() {

   var strtRulerUnits = app.preferences.rulerUnits; // Save Users ruler units

   app.preferences.rulerUnits = Units.PIXELS;       // work with pixels

   activeDocument.duplicate();                      // Duplicate Document

   activeDocument.resizeImage(1920, null, null, ResampleMethod.BICUBICSMOOTHER);

   app.preferences.rulerUnits = strtRulerUnits;     // Restore user ruler units 

}

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
Advocate ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

JJMack

Thank you

The first step has been made

Now it would serve another small code it should

Bring the processed document to the source document to fit it

All original image

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

Copy link to clipboard

Copied

Why what would that do for you.  You wrote about masking the 1920 document for faster performance for Photoshop is dealing with 1/8 the number of pixels the original  document has.  That you want to create a blurred mask using various blur tools.  I think you need to create that mask in the second 1920 document. Then once created you need copy that mask into the original document. Then Scale the copied mask  for the original document size.

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

Copy link to clipboard

Copied

Hi

Do you check my code? ( 9th reply of this thread )

I have posted two code one for Duplicate the image and another one for duplicate the layer.

-yajiv

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
Advocate ,
Aug 24, 2017 Aug 24, 2017

Copy link to clipboard

Copied

natrev

Now I've seen it

Thanks to everyone for help

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

Copy link to clipboard

Copied

LATEST

Hi geppettol66959005,

Please mark as correct answer if the answer is fulfil your requirement.

-yajiv

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

You mean align to the center?

if so why duplicate the image and resize instead of just the 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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

geppettol66959005  wrote

I have this need

I would duplicate the document in use

Resize to 1920px

Because you wrote 1920 it leads me to believes you want to display the resized image on a  1920x1080 display.  If an  image does not have a 16:9 aspect ratio and you resize it to fit within 1920x1080 pixels there will be borders.   Photoshop has a Plug-in named Fit Image that you can record in an action and batch to resize image to fit within 1920x1080 pixels.  Menu File >Automate>Fit Image record 1920width 1080 height.  Or you can use menu Scripts>Image Processor and fill in its dialog and have it resize images to fit within 1920x1080.  I will use Fit Image to do the resize.

If you do not  want boarders on images that do not have a 16:9 aspect Ratio you could try using Photoshop Content Aware Resize.   The will be distortion. Photoshop will try to preserve object it recognizes perspective,  However you should not expect square  and portrait aspect ration image to resize well into a wide 16:9 landscape Aspect ratio image.  Cropping to 16:9 also will not  work well with square and portrait images to much image content will be cropped off the resulting composition will not be acceptable.

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 ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

Hi,

can you provide a bit of background on the rationale behind your request, please?

Basically, you're downsampling an image ("Fit to Image" to a smaller size), and then upsampling it ("Fit to Image" back to the original size). Which, inherently, is going to cause a loss of quality – how much, it depends on the original image's size.

In other words, what you're asking for is a "quality loss machine", but at the same time "Without having too much loss of quality" – that's the puzzling part.

Davide

Davide Barranca - PS developer and author
www.ps-scripting.com

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
Advocate ,
Aug 23, 2017 Aug 23, 2017

Copy link to clipboard

Copied

You are right in asking why this is my request

I need to duplicate the document and resize it

To perform operations on level masks

Which then bring it on the original document and fit it into the image

I think in this passage I do not have much loss of quality.

Thanks for your help

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

Copy link to clipboard

Copied

To perform operations on level masks

Why would those not work on the fullers image?

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