Thread View: adobe.photoshop.scripting
18 messages
18 total messages
Started by Daniel_Laflor
Mon, 30 Mar 2009 11:01
Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Mon, 30 Mar 2009 11:01
Date: Mon, 30 Mar 2009 11:01
9 lines
1263 bytes
1263 bytes
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
Re: Action that resizes to specific uncompressed size? Please help!
Author: christoph_pfaffenbichler
Date: Mon, 30 Mar 2009 15:43
Date: Mon, 30 Mar 2009 15:43
8 lines
1239 bytes
1239 bytes
The M would have to stand for Megabytes. I don�t 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?
Re: Action that resizes to specific uncompressed size? Please help!
Author: Paul_R
Date: Tue, 31 Mar 2009 16:16
Date: Tue, 31 Mar 2009 16:16
48 lines
1780 bytes
1780 bytes
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;
}
Re: Action that resizes to specific uncompressed size? Please help!
Author: Michael_L_Hale
Date: Wed, 01 Apr 2009 14:22
Date: Wed, 01 Apr 2009 14:22
1 lines
771 bytes
771 bytes
I should note that the script only works correctly with 8bit images.
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Thu, 02 Apr 2009 06:51
Date: Thu, 02 Apr 2009 06:51
7 lines
1082 bytes
1082 bytes
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
Re: Action that resizes to specific uncompressed size? Please help!
Author: Paul_R
Date: Thu, 02 Apr 2009 19:02
Date: Thu, 02 Apr 2009 19:02
10 lines
1433 bytes
1433 bytes
Step 1 copy the code and paste it into ExtendScript Toolkit, this is the the editor that comes with Photoshop. This utility can be found in the relevant folder:- PC: C:\Program Files\Adobe\Adobe Utilities MAC: <hard drive>/Applications/Utilities/Adobe Utilities Save the script into the default scripts folder:- PC: C:\Program Files\Adobe\Adobe Photoshop CS#\Presets\Scripts MAC: <hard drive>/Applications/Adobe Photoshop CS#/ Presets/Scripts To run the script, have the document open that you want to resize, then File - Scripts and select the script you have just saved. 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. Hope this helps..
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Thu, 02 Apr 2009 19:57
Date: Thu, 02 Apr 2009 19:57
7 lines
1389 bytes
1389 bytes
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
Re: Action that resizes to specific uncompressed size? Please help!
Author: Mark_Walsh
Date: Thu, 02 Apr 2009 20:14
Date: Thu, 02 Apr 2009 20:14
3 lines
773 bytes
773 bytes
Change the first line to var SizeOfFile = 46.5
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Thu, 02 Apr 2009 20:43
Date: Thu, 02 Apr 2009 20:43
10 lines
1248 bytes
1248 bytes
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 :)
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Thu, 02 Apr 2009 20:59
Date: Thu, 02 Apr 2009 20:59
4 lines
810 bytes
810 bytes
By the way would the script (generated on my mac) also work on a Windows machine? Regards, Daniel Laflor
Re: Action that resizes to specific uncompressed size? Please help!
Author: Mark_Larsen
Date: Thu, 02 Apr 2009 21:05
Date: Thu, 02 Apr 2009 21:05
1 lines
950 bytes
950 bytes
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.
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Thu, 02 Apr 2009 21:32
Date: Thu, 02 Apr 2009 21:32
4 lines
915 bytes
915 bytes
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 ...
Re: Action that resizes to specific uncompressed size? Please help!
Author: Mark_Larsen
Date: Thu, 02 Apr 2009 21:48
Date: Thu, 02 Apr 2009 21:48
1 lines
791 bytes
791 bytes
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�
Re: Action that resizes to specific uncompressed size? Please help!
Author: Michael_L_Hale
Date: Fri, 03 Apr 2009 03:59
Date: Fri, 03 Apr 2009 03:59
54 lines
2330 bytes
2330 bytes
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;
}
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Fri, 03 Apr 2009 06:28
Date: Fri, 03 Apr 2009 06:28
9 lines
1555 bytes
1555 bytes
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
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Fri, 03 Apr 2009 11:51
Date: Fri, 03 Apr 2009 11:51
18 lines
1536 bytes
1536 bytes
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
Re: Action that resizes to specific uncompressed size? Please help!
Author: Paul_R
Date: Fri, 03 Apr 2009 13:01
Date: Fri, 03 Apr 2009 13:01
50 lines
1770 bytes
1770 bytes
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();
}
Re: Action that resizes to specific uncompressed size? Please help!
Author: Daniel_Laflor
Date: Fri, 03 Apr 2009 14:10
Date: Fri, 03 Apr 2009 14:10
8 lines
784 bytes
784 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads