Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


A script that automatically changes the size of the image, but it can't run now.

Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

A script that automatically changes the size of the image, but it can't run now.

Before printing, I need to change the size of the picture, otherwise the file is too big.

If I actually use the width of 100 mm, I need to keep it as 100 + 20 mm.

A good man wrote a script for me a few years ago, but now it can't run.

 

This script sometimes fails to change the size of the image properly, or reduces the size of the image, which is very dangerous.

 

Today, I manually changed the size of 1500 pictures, and I suddenly found this script very useful.

 

I hope the experts will show up and help me see what's wrong.

Thank you.

Note: the size I need is the size selected by white arrow (direct selection tool) + 20mm, 350dpi.

--------------------------------

The next one is semi-automatic and will not be saved automatically.

Main();  
function Main() {  
    try{var image = app.selection[0].images[0];}catch(e){return}  
    var imagePath = image.itemLink.filePath;  
    var myResolution=350;  
    var hScale=image.horizontalScale*(myResolution/image.actualPpi[0]);  
    var vScale=image.verticalScale*(myResolution/image.actualPpi[1]);  
    CreateBridgeTalkMessage();  
    function CreateBridgeTalkMessage() {  
        var bt = new BridgeTalk();  
        bt.target = "photoshop";  
        bt.body = myResizeImage.toString() + "\rmyResizeImage('" + imagePath + "'," + hScale + "," + vScale +","+myResolution+ ");";   
        bt.send();  
    }  
}  
function myResizeImage(imagePath, hScale, vScale,myResolution) {  
    for(var i=0;i<app.documents.length;i++)  if(app.documents[i].fullName.fsName==imagePath)return;  //if image opend   
    app.bringToFront();  
    app.preferences.rulerUnits = Units.MM;  
    var myFile = new File(imagePath);  
    var myDoc = app.open(myFile);  
    myDoc.resizeImage(undefined,undefined, myResolution,ResampleMethod.NONE);  
    var  w=myDoc.width.value * hScale*0.01;  
    var h=myDoc.height.value * vScale*0.01;  
    var k=w+15.00;  
    var j=h*k/w;  
    myDoc.resizeImage(k,j, myResolution,ResampleMethod.BICUBICSMOOTHER);  
    }

 

This one will be saved automatically

 ------------------

 

Main();  
function Main() {  
    try{var image = app.selection[0].images[0];}catch(e){return}  
    var imagePath = image.itemLink.filePath;  
    var myResolution=350;  
    var hScale=image.horizontalScale*(myResolution/image.actualPpi[0]);  
    var vScale=image.verticalScale*(myResolution/image.actualPpi[1]);  
    CreateBridgeTalkMessage();  
    function CreateBridgeTalkMessage() {  
        var bt = new BridgeTalk();  
        bt.target = "photoshop";  
        bt.body = myResizeImage.toString() + "\rmyResizeImage('" + imagePath + "'," + hScale + "," + vScale +","+myResolution+ ");";   
        bt.send();  
    }  
}  
function myResizeImage(imagePath, hScale, vScale,myResolution) {  
    for(var i=0;i<app.documents.length;i++)  if(app.documents[i].fullName.fsName==imagePath)return;  //if image opend   
    app.bringToFront();  
    app.preferences.rulerUnits = Units.MM;  
    var myFile = new File(imagePath);  
    var myDoc = app.open(myFile);  
    myDoc.resizeImage(undefined,undefined, myResolution,ResampleMethod.NONE);  
    var  w=myDoc.width.value * hScale*0.01;  
    var h=myDoc.height.value * vScale*0.01;  
    var k=w+12.00;  
    var j=h*k/w;  
    myDoc.resizeImage(k,j, myResolution,ResampleMethod.BICUBICSMOOTHER);  
    myDoc.save();  
    myDoc.close();
    }

 

TOPICS
Bug, Feature request, How to, Import and export, Performance, Scripting

Views

65

Likes

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
Explorer ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

LATEST

4-29.jpg

The width of the white arrow (direct selection tool) after selecting the image.

After selecting the drawing, run the script, open PS automatically and change the size automatically

Likes

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