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

getting targetsize one doc to another

New Here ,
Oct 29, 2008 Oct 29, 2008

Copy link to clipboard

Copied

Hi,

posted this in the Photoshop forum but was pointed at this scripting forum. I know nothing about scripting so please treat me like a child....... hopefully it's not to complicated < grin>.

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

I need to automatically rezize a photoshop document by using an action. Sounds pretty simple, yes. But the thing is that the flow needs to grab the individual/specific size from ANOTHER open document (different from time to time) to be used as the target size.... I need to make the grab the target size from a variable, so to speak.

I've tried to use the crop-tool to grab size and then use select all + crop on the other document, but no. Plus loads of workarounds.

It has to be a full auto function to be run from a droplet.

This is what it will be used for:

A faksimil scan from a newspaper page needs to get a broken side like it had been ripped out by hand. A shadow on the ripped edge as usual. Easy to do by hand. But the action flow will use a "template"document holding a pre-made layermask built with the right edgelook. The Action will rezize this to fit the original faksimil dokument and apply the ripped edge+ shadow on the faksimil document in one go. By loading the selection from the layermask over to the faksimil.

Anyone with the right kind of brain for this? My own seems to be out of question this time.

Thanks,

Nick
TOPICS
Actions and scripting

Views

363

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
Valorous Hero ,
Oct 29, 2008 Oct 29, 2008

Copy link to clipboard

Copied

Well I'm a little confused, but is this something like:-
This code assumes that you have two open documents.
The first document that was opened is the actual files size required.
The second document is the one that needs to be resized to the size of the first document.

To use: save the script as FileName.jsx (CS2/3/4) or FileName.js (cs or PS7) It is best to use "ExtendScript Toolkit" this comes with Photoshop. If not use a Text based editor. Do not use Word.
You can save the script anywhere you like.
In your action (to use the script) File - Scripts - Browse (to where you saved the script) and select it.

NB: It will make the document the EXACT same size as the first document!



if(app.documents.length == 2){

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

activeDocument = app.documents[0];

var Width = activeDocument.width.value;

var Height = activeDocument.height.value;

activeDocument = app.documents[1];

resize(Width,Height);

app.preferences.rulerUnits = startRulerUnits;

}

function resize(Width,Height) {

var ad = new ActionDescriptor();

ad.putUnitDouble( app.charIDToTypeID('Wdth'), app.charIDToTypeID('#Pxl'), Width );

ad.putUnitDouble( app.charIDToTypeID('Hght'), app.charIDToTypeID('#Pxl'), Height );

ad.putEnumerated( app.charIDToTypeID('Intr'), app.charIDToTypeID('Intp'), app.stringIDToTypeID('bicubicSharper') );

executeAction( app.charIDToTypeID('ImgS'), ad, 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
Explorer ,
Oct 29, 2008 Oct 29, 2008

Copy link to clipboard

Copied

> NB: It will make the document the EXACT same size as the first document!

Which means if the aspect ratios are different, the resized image will be distorted.

This function will resize the doc to fit withing the bounds of the other.
There's no distortion but there may be blank areas on two of the edges.

function fitImage(width, height) {
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

var desc = new ActionDescriptor();
desc.putUnitDouble( cTID('Wdth'), cTID('#Pxl'), width );
desc.putUnitDouble( cTID('Hght'), cTID('#Pxl'), height );

var fitId = sTID('3caa3434-cb67-11d1-bc43-0060b0a13dc4');
return executeAction(fitId , desc, DialogModes.NO );
};

-X

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
New Here ,
Oct 30, 2008 Oct 30, 2008

Copy link to clipboard

Copied

Hey guys,

I'll try this during the weekend and let you know!

Very much appreciated and I realize I should learn this kind of stuff. I'm completely new to scripting, but quite experinced as a PS user since many years. I've missed an important part on that trip. That's for sure.

Thanks a lot for your support!

N

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
New Here ,
Oct 31, 2008 Oct 31, 2008

Copy link to clipboard

Copied

LATEST
Eh, what can a happy man say you're my heroes.

Yes, it works...it was hard to believe at first sight.

The script is a part of the Action now. It simply resizes the template document which holds an Alphachannel. This Alphachannel has a ripped edge along the bottom and right side. The Action calls up that document from HD.

The script makes it the same size as the original faksimil which I've open by hand. The samesize in turn makes it *possible* to load the Alpha selection by using Selection > Load over onto the original faksimil. If the size diffs, the load command is greyd out. It's not possible to read the Alpha from another document then.The script solved the baseproblem perfectly well.

The backgroundlayer is converted to a layer 0 by a doubleclick. Then the edge is cut from the selection (coming from the Alpha) by a simple delete. The layer style is set to dropshadow and adjusted for a typical value for spread and opacity. In an Action variant a Stop may be set here for manual adjustment, but I probably will run it on the preset values without that.

The Canvas is bumped up in size a little bit to give more space for the soft drop shadows to spread.

The layer is flatten. The Alpha document is closed. The action is dependent on the location of the Alphadocument. Move it and the action cracks down.

It works from the droplet too, and I'll probably will let this close down the faksimil to as this is a dropletflow. A bunch of faksimils may be dumped on it. The documents would clog up the screen. I'll,build a few variants and see what works best.

So, the script made it possible! This was quite nice, my friends. I'm really greatful.

I just have a few questions;

1) It doesn't seems to be a problem with the distortion which I was expecting, but since the code was given I was hooked on it to build it in. However, I tried in a blind manner to put it into the first basic script where I thought it could belong. But it did not work that way. I've tried a lot of different ways, didn't make any notes I'm afraid. It's just a ripped edge and the eye will probably not pay any attention to a slight distortion. Anyway, if you do have any suggestions on how to bump that function in I'll listen and follow.

2) When packing the whole thing into the droplet, will the droplet depend on the script to load or is it bumped into the droplet like the rest of the action? It will still look for the Alpha carrier on desk, probably also for the script?

3) Do you have any suggestions on good a easy to grab books for a beginners brain when trying to let it be a larger part of my life than it has been so far. I can see the potential. I'm very used to pretty advanced actionbuilding, but the scripting is real power. No doubt.

Thanks again and have a very nice weekend!

Nick the Cow

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