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

Action that resizes to specific uncompressed size? Please help!

Guest
Mar 30, 2009 Mar 30, 2009
Hi kind people

I do stock photography and more often than not I have to resize (mostly downsize but occationally upsize) to a specific uncompressed size. This happens when a full resolution file is not tack sharp and I have to resize it to make it sharp. I have 5 different sizes I can resize to, depending on how much I have to downsize. Therefore a set of actions would be fantastic.
Is there a way to make an action that does that?

By the way does anybody know what the letter "m" stands for when the image is 60.2M (in the bottom left corner of the image when open in PS - given you have selected "document size" in the fly out menu).

All the best,
Daniel Laflor
TOPICS
Actions and scripting
3.0K
Translate
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
Community Expert ,
Mar 30, 2009 Mar 30, 2009
The M would have to stand for Megabytes.

I dont quite understand why You want to downsize to specific file-sizes (instead of file-dimensions) though.
It should be easy enough to record the five Actions based on dimensions in the Actions Panel, but I guess it would be a bit more time-consuming to create a Script for file-size-specific rescaling.
On the other hand if You always operate on original files of the same size one should be able to get the necessary scaling-factors without too much difficulty.

Do You work on the RAW-files?
And is sharpening out of the question on principle?
Translate
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
Valorous Hero ,
Mar 31, 2009 Mar 31, 2009
I wonder if this is what you are looking for?
This was writtem by Mike Hale.


var SizeOfFile = prompt("Please Enter Size In Megabytes",48)

if (SizeOfFile > 0) resizeToMB( SizeOfFile );



function resizeToMB( size_in_MB ) {

var current_units = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var width_pixels = activeDocument.width;

var height_pixels = activeDocument.height;

var channel_count = activeDocument.channels.length;

var final_size = ( 1024 * 1024 * size_in_MB ) / channel_count;

var image_bytes = width_pixels * height_pixels;

var image_scale = Math.sqrt( final_size/ image_bytes );

var final_width = width_pixels * image_scale;

var final_height = height_pixels * image_scale;

var final_dpi = activeDocument.resolution;

if ( image_scale > 1 ) {

activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSMOOTHER );

} else {

activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSHARPER );

}

preferences.rulerUnits = current_units;

}

Translate
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
Guru ,
Apr 01, 2009 Apr 01, 2009
I should note that the script only works correctly with 8bit images.
Translate
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
Guest
Apr 01, 2009 Apr 01, 2009
Hi Paul and Michael
First I want to very much appreciate your help. Secondly I must bluntly admit that I have no idea how to implement the above (wonderful, I'm sure) script. Could you please help me with that? A 3 step tutorial would be wonderful. And to make it more practical, let's say I want to downsize an image to 46.5mb. How would the script look like and how do I activate it?

Again thank you very much for your advise.

All the best,
Daniel Laflor
Translate
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
Valorous Hero ,
Apr 02, 2009 Apr 02, 2009
Step 1 copy the code and paste it into ExtendScript Toolkit, this is the the editor that comes with Photoshop.<br />This utility can be found in the relevant folder:-<br />PC: C:\Program Files\Adobe\Adobe Utilities<br />MAC: <hard drive>/Applications/Utilities/Adobe Utilities<br />Save the script into the default scripts folder:-<br />PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts <br />MAC: <hard drive>/Applications/Adobe Photoshop CS#/ Presets/Scripts<br />To run the script, have the document open that you want to resize, then File - Scripts and select the script you have just saved.<br />It will then prompt you for the size in Megabytes in this case enter 46.5 and enter. This will resize the document ready for you to save.<br />Hope this helps..
Translate
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
Guest
Apr 02, 2009 Apr 02, 2009
I AM A VERY, VERY HAPPY YOUNG LAD :)
This is such a timesaver and I am so exited that it actually works. Great job you guys. I bow down in gratitude :)

And just to round it all up towards total perfection, how can I make an action that do not prompt for entering the size in mb, but actually register my recording of for instance 46.5Mb. That would just make my year (and we are only in april ... wouldn't that just be something huh?). When I record an action using the script, it still prompt me for the desired size even though I tried to register it in the recording (I know I am repeating my question ... but I just want to make myself clear). :)

All the best,
Daniel Laflor
Translate
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
Advocate ,
Apr 02, 2009 Apr 02, 2009
Change the first line to

var SizeOfFile = 46.5
Translate
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
Guest
Apr 02, 2009 Apr 02, 2009
Hi everybody

I don't want to sound crazy or overly exited about small things in life, but I must really acknowledge you guys for being so helpful, and especially Michael Hale for writing the original script.

I also want to ask if I may share this script with other photographers via my blog? Is that ok with you Michael? I will of course mention where it came from :)

All the best,
Daniel Laflor

Ps. Right now I am so happy I just feel like dancing in the streets in orange garments singing "Hare krishna, hare krishna, rama rama :)
Translate
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
Guest
Apr 02, 2009 Apr 02, 2009
By the way would the script (generated on my mac) also work on a Windows machine?

Regards,
Daniel Laflor
Translate
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 ,
Apr 02, 2009 Apr 02, 2009
The posted script is JavaScript which makes it platform independent. Enjoy!!! Acknowledging the author always makes good netiquette you could do this by including a commented section at the head thats if Mike would want that. The code is posted open.
Translate
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
Guest
Apr 02, 2009 Apr 02, 2009
Ok. I like platform independence :)
Lets see what Mike says. I have a feeling this script could get thousands of downloads because of its VERY relevant usability for microstock photographers.

All the best ...
Translate
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 ,
Apr 02, 2009 Apr 02, 2009
Add a catch for non 8bit images and batch a whole bunch of files then you really will be having fun "Hare krishna, hare krishna, rama rama" you could even catch the scripting bug
Translate
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
Guru ,
Apr 02, 2009 Apr 02, 2009
Any code I post is open source unless the comments say otherwise. I wrote that so long ago I can't remember if I posted it here or at PS-Scripts.

Here is a version that checks for bit depth.

var SizeOfFile = prompt("Please Enter Size In Megabytes",48);// defaults to 48mb. Change 48 to whatever size needed.
// var SizeOfFile = 48;// or comment out line above and uncomment this line to hardcode size

if ( SizeOfFile > 0 ) resizeToMB( SizeOfFile );

function resizeToMB( size_in_MB ) {

var current_units = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var width_pixels = activeDocument.width;

var height_pixels = activeDocument.height;

var channel_count = activeDocument.channels.length;

if( activeDocument.bitsPerChannel == BitsPerChannelType.ONE ){// let's not resize bitmap images
return;
}
if( activeDocument.bitsPerChannel == BitsPerChannelType.EIGHT ){
var final_size = ( 1024 * 1024 * size_in_MB ) / channel_count;
}

if( activeDocument.bitsPerChannel == BitsPerChannelType.SIXTEEN ){
var final_size = (( 1024 * 1024 * size_in_MB ) / channel_count)/2;
}
var image_bytes = width_pixels * height_pixels;

var image_scale = Math.sqrt( final_size/ image_bytes );

var final_width = width_pixels * image_scale;

var final_height = height_pixels * image_scale;

var final_dpi = activeDocument.resolution;

if ( image_scale > 1 ) {

activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSMOOTHER );

} else {

activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSHARPER );

}

preferences.rulerUnits = current_units;

}
Translate
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
Guest
Apr 02, 2009 Apr 02, 2009
Thanks Michael
Since it is the pixel count that matters in this method I can see that I have to double the MB when dealing with 16bit images (with the new script). That actually means I would want to use the original script since that script apparently resizes 16 bit images to the amount of pixels that the equivalent image in 8 bit contains uncompressed (relating to the mb you enter in the prompt dialogue). The megabyte output is double the number you enter however , and that may confuse most people, but the script does its thing correctly, and people will just have to accept that. And since I will use it as part of an action stating for instance XXXL, XXL, XL, L, M etc. that is the only thing people have to relate to; they just have to click the button :)

But in case one needs to make a 16 bit image a specific size uncompressed now we also have a version for that.

You rock Michael :)

All the best,
Daniel Laflor
Translate
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
Guest
Apr 03, 2009 Apr 03, 2009
Hey guys

Just to let you know I am still as exited about this script as I have ever been :)

And now that I am in Wonderland anyway why not make two more wishes:

1.
would one of you guys adjust the script so that I have a version that only resizes (upsizes) to 50 megabyte IF the file is LESS than 50 megabyte (and yes I actually mean LESS ;)) And do not do anything if the file is above 50 megabyte.

2.
I have made an action that generates jpgs from folders with layered tiffs. However some clients do not want jps with working paths, and the working paths stay in the jpgs when generated from tiffs. Would some kind soul write a script that says something like: "if working path is present, delete it". Then I could insert that into the action and sleep tight.

I would really, really be thankful for this help. It would ease my workflow sooo much.

SCRIPTING RULES!

All the best,
Daniel Laflor
Translate
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
Valorous Hero ,
Apr 03, 2009 Apr 03, 2009
Here is the first one...


if(documents.length) resizeToFiftyMeg();

function resizeToFiftyMeg(){

var SizeOfFile = 50; //This is the actual size required.

var current_units = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

var width_pixels = activeDocument.width;

var height_pixels = activeDocument.height;

var channel_count = activeDocument.channels.length;

var image_bytes = width_pixels * height_pixels;

var actual =((image_bytes/1024/1024)*channel_count).toFixed(2);

if(actual >= SizeOfFile) return;

var final_size = ( 1024 * 1024 * SizeOfFile ) / channel_count;

var image_scale = Math.sqrt( final_size/ image_bytes );

var final_width = width_pixels * image_scale;

var final_height = height_pixels * image_scale;

var final_ppi = activeDocument.resolution;

activeDocument.resizeImage( final_width, final_height, final_ppi, ResampleMethod.BICUBICSMOOTHER );

preferences.rulerUnits = current_units;

}


and the second..

if(activeDocument.pathItems.length){
app.activeDocument.pathItems.removeAll();
}
Translate
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
Guest
Apr 03, 2009 Apr 03, 2009
Somebody wake me up. This is simply too good to be true :)

It simply works!!!

Thanks a bunch Paul. Good thoughts from me to you.

All the best,
Daniel Laflor
Translate
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
Guest
Dec 15, 2009 Dec 15, 2009

Hi guys

I started this thread back in April and I've been using the scripts developed back then eagerly.

I have tried to combine the scripts with some actions and now I am getting some strange behaviour where the script opens the preferences for units and rulers. What seems to be the problem? The script looks like this:

var SizeOfFile = 50

if (SizeOfFile > 0) resizeToMB( SizeOfFile ); 

function resizeToMB( size_in_MB ) { 

  var current_units = preferences.rulerUnits; 

  preferences.rulerUnits = Units.PIXELS; 

  var width_pixels = activeDocument.width; 

  var height_pixels = activeDocument.height; 

  var channel_count = activeDocument.channels.length; 

  var final_size = ( 1024 * 1024 * size_in_MB ) / channel_count; 

  var image_bytes = width_pixels * height_pixels; 

  var image_scale = Math.sqrt( final_size/ image_bytes ); 

  var final_width = width_pixels * image_scale; 

  var final_height = height_pixels * image_scale; 

  var final_dpi = activeDocument.resolution; 

  if ( image_scale > 1 ) { 

    activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSMOOTHER ); 

} else { 

    activeDocument.resizeImage( final_width, final_height, final_dpi, ResampleMethod.BICUBICSHARPER ); 

  preferences.rulerUnits = current_units; 

}

Kind regards,

Daniel Laflor

Translate
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
Guest
Dec 15, 2009 Dec 15, 2009

By the way this is what the whole action looks like:

Screen shot 2009-12-15 at 12.33.53 PM.JPG

Any suggestions?

Translate
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
Guru ,
Dec 15, 2009 Dec 15, 2009

I'm not sure what is going on, but here is a version that does not change the rulerIUnit.

var SizeOfFile = 50

if (SizeOfFile > 0) resizeToMB( SizeOfFile );

function resizeToMB( size_in_MB ) {
     var width_pixels = activeDocument.width.as('px');
     var height_pixels = activeDocument.height.as('px');
     var channel_count = activeDocument.channels.length;
     var final_size = ( 1024 * 1024 * size_in_MB ) / channel_count;
     var image_bytes = width_pixels * height_pixels;
     var image_scale = Math.sqrt( final_size/ image_bytes );
     var final_width = width_pixels * image_scale;
     var final_height = height_pixels * image_scale;
     var final_dpi = activeDocument.resolution;
     if ( image_scale > 1 ) {
          activeDocument.resizeImage( new UnitValue(final_width,'px'), new UnitValue(final_height,'px'), final_dpi, ResampleMethod.BICUBICSMOOTHER );
     } else {
          activeDocument.resizeImage( new UnitValue(final_width,'px'), new UnitValue(final_height,'px'), final_dpi, ResampleMethod.BICUBICSHARPER );
     }
}

Translate
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
Guest
Dec 15, 2009 Dec 15, 2009

It still does the same weird thing with your script.

I experimented and removed the resize script from the action set and everything else runs smoothly when its not there.

When running the resize script as a separate thing on an open image it works fine. However if I run the script on a batch of images the same lame dialog box with the units appears, even when using your script without the ruler preferences. Any suggestions?

Kind regards,

Daniel Laflor

Translate
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
Guru ,
Dec 15, 2009 Dec 15, 2009
LATEST

Does it appear with every image or just some? Can you post a screenshot of the dialog?

Translate
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