Copy link to clipboard
Copied
How does Photoshop determine the image size in this window:
This differs drastically to the actual file size when checked in Finder, so what does this number actually represent? The number of pixels in the image? Is there a way to access this number with Javascript?
Copy link to clipboard
Copied
Looks like it just multiplies the amount of pixels by the color depth.
So if you set it to 1x1px it will show 3 bytes because it's three color channels of 8bit color.
100 * 100 * 3 * 1byte = 120,000 bytes or 117.1875KB.
This would be the size of a flat uncompressed bitmap file, with multiple layers and compression the actual file size will of course be different.
Copy link to clipboard
Copied
Yeah, that's sounds like the closest way of calculating it, although the larger the image, the more inaccurate the results.
I basically needed to make sure my images were at least 10mb, so I just figured out what height by width I needed in pixels at 300 resolution in order for an image to be at 10mb (layers etc didn't affect the size calculation in that window), and then just wrote a script to increase the file size by 5 percent (whilst constraining proportions) until it reached that if it didn't initially. It ended up looking like this:
var doc = activeDocument
var setPercent = 0.05
var minSize = 3500000
if(doc.width * doc.height < minSize) {
var correctSize = false;
var docHeight = doc.height
var docWidth = doc.width
while(correctSize === false){
var setPercentOfWidth = docWidth * setPercent
var setPercentOfHeight = docHeight * setPercent
var adjustedWidth = docWidth + setPercentOfWidth
var adjustedHeight = docHeight + setPercentOfHeight
if(adjustedWidth * adjustedHeight >= minSize){
correctSize = true;
} else {
docWidth = adjustedWidth
docHeight = adjustedHeight
}
}
doc.resizeImage(adjustedWidth, adjustedHeight)
}
If you have any suggestions as to how to improve this, I'd love to hear them!
Copy link to clipboard
Copied
Where I couldn't find anything in the Javascript ref guide, in the Javascript tools guide, there is mention of a property of the File object, called length. So, if you saved your document then you could access the size through File.
var foo = new File("~/Desktop/bar.tif");
alert(foo.length)
This returns a number in all bytes of the length of the file.
I've found that the number your looking at in that dialog can vary drastically due to all of the things you've mentioned. Have you tried looking at the VB Scripting ref, or maybe the Applescript Ref materials? One of those may just have what you need.
Copy link to clipboard
Copied
Yes, I initially went down the .length route on the actual file, but that size would be affected by layers etc, whereas the number in that dialog isn't. The images I was dealing with were being uploaded to a website, and if they were too small they would appear smaller alongside those correct in size. Over the year(s), the retouch team just figured out that if they were at least over 10M in that dialog, they would display correctly, but it's obvious now that it was ultimately a dimension/resolution issue.
Copy link to clipboard
Copied
You can probably get a decent estimate of file size with an averaged compression ratio taking into consideration what format and compression settings you'll be using. Or actually write a temp file.