Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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;
}
if(activeDocument.pathItems.length){
app.activeDocument.pathItems.removeAll();
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
By the way this is what the whole action looks like:
Any suggestions?
Copy link to clipboard
Copied
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 );
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Does it appear with every image or just some? Can you post a screenshot of the dialog?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now