🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.photoshop.scripting
Article #73

Re: Action that resizes to specific uncompressed size? Please help!

#73
From: Michael_L_Hale
Date: Fri, 03 Apr 2009 03:59
54 lines
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;

}
Technical Details
Message-ID: <59b87301.12@webcrossing.la2eafNXanI>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
References: <59b87301.-1@webcrossing.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Thread: f5839,21e37c569c4141d3
X-Google-Attributes: gidf5839,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Michael_L_Hale@adobeforums.com
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!newshub.sdsu.edu!webcrossing
Newsgroups: adobe.photoshop.scripting
Subject: Re: Action that resizes to specific
 uncompressed size? Please help!
Message-ID: <59b87301.12@webcrossing.la2eafNXanI>
Date: Thu, 2 Apr 2009 20:59:11 -0700
References: <59b87301.-1@webcrossing.la2eafNXanI>
Lines: 61
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit