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

Photoshop Extendscript: get active document weight?

Contributor ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Hello,

Is there a way to get the weight of the active Photoshop CS6 document?

I tried this, but the result is not accurate enough:

thisDoc = app.activeDocument;

// ----------- get the number of pixels
var savedUnitType = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var px = thisDoc.width.value * thisDoc.height.value;
app.preferences.rulerUnits = savedUnitType;

// ----------- get the number of bits/pixel
var bits = getDocBits(thisDoc);

// ----------- 
alert(px * thisDoc.resolution * bits / 1024 / 1000 / 1000); // Mb

function getDocBits(thisDoc) {
	var bits = thisDoc.bitsPerChannel;
	if (bits == BitsPerChannelType.EIGHT) {
		return 8;
	}else if (bits == BitsPerChannelType.ONE) {
		return 1;
	}else if (bits == BitsPerChannelType.SIXTEEN) {
		return 16;
	}else if (bits == BitsPerChannelType.THIRTYTWO) {
		return 32;
	}
}

 

jsx.jpg

TOPICS
Actions and scripting

Views

570

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

Guide , Jan 11, 2023 Jan 11, 2023

 

alert(px * thisDoc.resolution * bits / 1024 / 1000 / 1000);

 

It seems that you have confused the units of data transfer rate and data storage units.

 

1 mb = 1024 kb

1 kb = 1024 bytes

1 byte = 8 bits

 

doc size in bytes = px width * px height * number of channels * bit depth 

 

thisDoc = app.activeDocument;

// ----------- get the number of pixels
var savedUnitType = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var px = thisDoc.width.value * thisDoc.height.value;
app
...

Votes

Translate

Translate
Adobe
LEGEND ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Are you trying to get compressed size on disk or uncompressed size during editing? Just counting pixels isn't enough because there could be other elements such as adjustment layers, shapes, notes, snapshots, etc.

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 ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Given the desired final size (width and height) for printing the document, I'm trying to know if I can set its resolution to 480, 360 or 300 dpi *without* enlarge it (I only want to use the ResampleMethod.BICUBIC method during resizing).

At this time, I have three scripts: one for each desired resolution and I'm trying to make just one, with a test according to the document weight.

If my question isn't very easy to understand (sorry for my poor english), I'll join more screen captures.

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
LEGEND ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Just use the height and width divided by finished size.

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 ,
Jan 12, 2023 Jan 12, 2023

Copy link to clipboard

Copied

LATEST

Thank you for your quick answers 🙂

Based on your answer, Lumigraphics, I wrote this little function to return the max document resolution for a given desired Width ou Height in CM:

 

function getMaxDocResolution(thisDoc, finalDimCm, side) { // return max doc resolution for a given desired Width ou Height in CM
	// side : 'width' || 'w' || 'height' || 'h' (default)
	var side = side || 'w';
	side = side.substring(0, 1).toLowerCase();
	
	var finalDimCm = finalDimCm || 1; // todo : check if finalDimCm is a number greater then 0
	
	var savedRulerUnit = app.preferences.rulerUnits;
	app.preferences.rulerUnits = Units.CM;
	var docDimCm = (side == 'h')? thisDoc.height.value : thisDoc.width.value;
	app.preferences.rulerUnits = savedRulerUnit;
	
	return Math.floor(thisDoc.resolution * docDimCm / finalDimCm);
}

 

 

 

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
LEGEND ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

You can also look at Image Processor Pro to handle this.

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
Guide ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

 

alert(px * thisDoc.resolution * bits / 1024 / 1000 / 1000);

 

It seems that you have confused the units of data transfer rate and data storage units.

 

1 mb = 1024 kb

1 kb = 1024 bytes

1 byte = 8 bits

 

doc size in bytes = px width * px height * number of channels * bit depth 

 

thisDoc = app.activeDocument;

// ----------- get the number of pixels
var savedUnitType = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var px = thisDoc.width.value * thisDoc.height.value;
app.preferences.rulerUnits = savedUnitType;

// ----------- get the number of bits/pixel
var bits = getDocBits(thisDoc);
// ----------- 
alert(px * bits * thisDoc.activeChannels.length / 1024 / 1024/ 8 ); // Mb

function getDocBits(thisDoc) {
	var bits = thisDoc.bitsPerChannel;
	if (bits == BitsPerChannelType.EIGHT) {
		return 8;
	}else if (bits == BitsPerChannelType.ONE) {
		return 1;
	}else if (bits == BitsPerChannelType.SIXTEEN) {
		return 16;
	}else if (bits == BitsPerChannelType.THIRTYTWO) {
		return 32;
	}
}

 

 

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