Skip to main content
Known Participant
July 11, 2019
Question

Total Pixels of an Image

  • July 11, 2019
  • 3 replies
  • 1997 views

Hi,

I wanted to find the total pixels of an image as I have some rejections from Apple for the images above 4 million pixels.

Is there Script or any Batch method we can use to process the images?

Arvind

This topic has been closed for replies.

3 replies

SuperMerlin
Inspiring
July 11, 2019
Known Participant
July 11, 2019

Thanks Tom for the suggestion.

I wanted to check Photoshop if the images are of more than 4 Million pixels.

Resize the Image in a proportion and the pixel of the should come to less than 4 Million (3.99 million)

If this is possible please help me with it.

regards

Arvind

JJMack
Community Expert
Community Expert
July 11, 2019

Working in Units Pixels Tom check the canvas size,  If its over your limit you can resize the image however you need to work out the math to account for the images Aspect Ratio  Current width/current height. My maths skills are not as good as they use to be it would take me some time to come up with the right formula come up the percent reduction needed to  reduce the size to just under 4mp. you need to reduce both the width and height by the same percentage to come.  You know the Aspect ratio and you know the limit is 4mp so you can calculate what the width and height need to be. Then you then calculate the percent the image width and high need to be reduced by.

JJMack
JJMack
Community Expert
Community Expert
July 11, 2019

I think my formula has the correct math. However I do not know JavaScript of its Math functions or  what type or precision  or how to handle  My resize function always resizes within 800 pixels of 4MP or less Square 1:1 Aspect ration resize exactly to 4MP however  3:2 and 4:3 common camera Aspect Ratio resize hundreds of Pixels less than 4MP and 16:9 aspect ratio image resize 500 pixel over 4MP.

Perhaps if you know Javascript and Photoshop you can fix my code.

/* ==========================================================

// 2019 John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// ensure at least one document open

if (!documents.length) alert('There are no documents open.', 'No Document');

else {

        // declare Global variables

        //main(); // at least one document exists proceed

        app.activeDocument.suspendHistory('4MP','main()');

}

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

//                            main function                                  //

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

function main() {

        // declare local variables

        var orig_ruler_units = app.preferences.rulerUnits;

        var orig_type_units = app.preferences.typeUnits;

        var orig_display_dialogs = app.displayDialogs;

        app.preferences.rulerUnits = Units.PIXELS;          // Set the ruler units to PIXELS

        app.preferences.typeUnits = TypeUnits.POINTS;   // Set Type units to POINTS

        app.displayDialogs = DialogModes.NO;                // Set Dialogs off

        try { code(); }

        // display error message if something goes wrong

        catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }

        // catch(e){$.writeln(e)}

        app.displayDialogs = orig_display_dialogs;          // Reset display dialogs

        app.preferences.typeUnits  = orig_type_units;   // Reset ruler units to original settings

        app.preferences.rulerUnits = orig_ruler_units;  // Reset units to original settings

}

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

//                           main function end                               //

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

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

// The real code is embedded into this function so that at any point it can return //

// to the main line function to let it restore users edit environment and end      //

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

function code() {

        if (activeDocument.width.value * activeDocument.height.value >= 4000000)  {

                //alert("Image Size = " + activeDocument.width.value * activeDocument.height.value + " Pixels");

                var resizePercent=(Math.sqrt(4000000/(activeDocument.height.value/activeDocument.width.value)))/activeDocument.width.value;

                activeDocument.resizeImage(activeDocument.width.value*resizePercent, activeDocument.height.value*resizePercent); // user default interpolation

                alert("New Size = " + activeDocument.width.value * activeDocument.height.value + " Pixels");

        }

}

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

//                      Helper Functions                                        //

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

JJMack
Tom Winkelmann
Inspiring
July 11, 2019

For single images you can use something like this...

#target photoshop

if (activeDocument.width * activeDocument.height >= 4000000)

    alert("Image contains more than 4 mio pixels!");

else(alert("Image accepted!"));

If you want a batch method, we have to know what to do with the images with more than 4mio pixels (delete/move/open/crop/...?)

SuperMerlin
Inspiring
July 11, 2019

Shouldn't that figure be times by activeDocument.channels.length ?