I use the Fit Image script quite a bit. For sizing images that will end up on the blog, batching out files for proofs, etc. I have it written into many of my actions.
Up until a few days ago, if you opened any action that I've recorded and expanded out the Fit Image step, you would see the dimensions (in pixels) that were recorded. Then, I started getting an error message for any action that used Fit Image. The error message was "Javascript code was missing".
I checked my scripts folder and the Fit Image script is there. Nothing has changed. I even used Time Machine to go back a few weeks and see if anything had been deleted. Nothing.
I tried to write a new action using Fit Image and now, instead of the expanded view showing the size in pixels, it's showing in inches! When I manually use Fit Image, the dialog box comes up with pixels ONLY, so why is it that the recorded step is shown in inches?
I've gone so far as to uninstall CS4 and reinstall it. The first thing I did was record an action and I'm getting the same results. Why would this just change and does this mean I have to re-record all my actions that use Fit Image?
Any ideas or insight?
Fit Image is independent of your ruler settings. That's what I was saying originally. In previous versions of Photoshop, the action was recorded with a pixel value, reflecting the parameters of Fit Image.
In the current version, Fit Image also only supports pixels, but the value is being recorded in inches. It's already been determined by Adobe as a bug in the Javascript, not Photoshop code.
With my CS3 actions, the action step was recorded as a Javascript step. Just as you stated, but I could expand the step and see that actual pixel value for that step.
I'm hoping they resolve this quickly, but in the meantime, I've re-recorded the Fit Image step for all the actions I have that use it.
Pain in the butt...but it works for now. I'm assuming when they fix it, I'll have to do this all over again! :)
However, my personal experience differed in that the actions I recorded in CS2 and CS3 would not work with CS4. I was getting error messages about the Javascript missing.
This was confusing as I knew for a fact it was NOT missing. When I shrugged and re-recored that step, the new Fit Image step was no longer a Javascript AND it was not recorded in a pixel value, but in inches. Did not matter how I had my rulers set up.
So, as you have fixed this problem. Is there a simple way for the rest of us code challenged users to resolve this issue?
I appreciate that you jumped in and are trying to help. Thank you!
CS2 and prior recording of the plug-in fit image were recorded as step Fit Image not as a script path step. These actions should still work for when Photoshop starts up the CS4 Fit Image scripts register as the plug-in Automate>Fit Image. When these action are played and the plug-in step Fit Image get played it is looking for the registered Fit Image Plug-in Photoshop should run the CS4 Fit Image Script.
The bug in Fit Image is very minor. One day I used fit image on a image that was 1080 x 1080 and fit image was set to 1200 x 1200 the resulting image turned out to be 1201 x 1200 one side was one pixel off there were 1200 extra pixels.
Reading the CS3 Fit Image Script I saw this:
docRatio = docWidth / docHeight; // decimal ratio of original width/height
// NOTE - ccox - 17 Aug 2004 - I added the rounding by 0.5
// this should solve reported cases of fit image being off by 1 (always under)
// NOTE - elr - 3 May 2006 - keep original aspect ratio
newWidth = width;
newHeight = ((1.0 * width) / docRatio) + 0.5; // decimal calc
newHeight = 1 * newHeight; // make integer
if (newHeight > height) {
newWidth = 0.5 + docRatio * height; // decimal calc
newWidth = 1 * newWidth; // make integer
newHeight = height;
}
Someone fixed fit image not to be one pixel under. I thought this fix most likely cause my one over problem so I stuck in some alerts to see the numbers. Looked like the multiply by one to round did not round and I thought the .5 value perhaps would work better if it were .4. So I changed to code to
docRatio = docWidth / docHeight; // decimal ratio of original width/height
// NOTE - ccox - 17 Aug 2004 - I added the rounding by 0.5
// this should solve reported cases of fit image being off by 1 (always under)
// rounding by .5 seem to make some sides 1 Px large change to .4 and used math round to round JJMack
// NOTE - elr - 3 May 2006 - keep original aspect ratio
newWidth = width;
newHeight = ((1.0 * width) / docRatio) + 0.4; // decimal calc
newHeight = Math.round(newHeight); // make integer
if (newHeight > height) {
newWidth = 0.4 + docRatio * height; // decimal calc
newWidth = Math.round(newWidth); // make integer
newHeight = height;
}
The name of my script file is "My Fit Image.jsx" I renamed Adobe file to "Fit Image.jsx.Adobe" My script is in My Photoshop Script tree which I linked to Photoshop's Presets\Script\ by placing a shortcut to my tree into into Photoshop's Script directory. "My Fit Image.jsx" registers itself as Automate>Fit Image...
<name>$$$/JavaScripts/FitImage/Name=Fit Image...</name>
<about>$$$/JavaScripts/FitImage/About=Fit Image Version 10.0 By Quality Process^r^rCopyright 2007 Adobe Systems Incorporated. All rights reserved.^r^rResizes a document constrained by the given bounds.^r^rJohn J. McAssey Modified Version^rFixed the one side one pixel to long problem^rand changed the interpolation Method used^rUpsizing will use Bicubic Smoother^rDownsizing Bicubic Sharper^rInstead of just using Bicubic for all resizing like Adobe did.</about>
automate
// resize the image using a good conversion method while keeping the pixel resolution
// and the aspect ratio the same
app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBIC);
To this:
// resize the image using a good conversion method while keeping the pixel resolution
// and the aspect ratio the same
//app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBIC);
if ( newWidth > app.activeDocument.width || newHeight > app.activeDocument.height ) { app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBICSMOOTHER); }
else { app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBICSHARPER); }
I opened up the Fit Image script and changed lines 104-106 to match your suggestion. It did not resolve the issue for me.
Interesting sidenote:
When testing this change, I recorded an action and used File>Automate>Fit Image (CS4) and the recorded step showed Fit Image with the result in inches.
I recorded an action again, only this time I used File>Scripts>Browse and loaded the Fit Image script from the default CS4 location and the recorded step showed Scripts as the recorded step.
I'm assuming Adobe will be addressing this in an update at some point or am I left to my own devices on this? Would it be helpful if I posted the entire script that's included with CS4?
function ResizeTheImage(width, height) {
var oldPref = app.preferences.rulerUnits;
var docWidth;
var docHeight;
var docRatio;
var newWidth;
var newHeight;
var resolution = app.activeDocument.resolution;
app.preferences.rulerUnits = Units.PIXELS; // save old preferences
// original width, height
docWidth = (1.0 * app.activeDocument.width * resolution) / 72.0; // decimal inches assuming 72 dpi (used in docRatio)
docHeight = (1.0 * app.activeDocument.height * resolution) / 72.0; // ditto
if (docWidth < 1.0 || docHeight < 1.0) return true; // error
if (width < 1 || height < 1) return true; // error
docRatio = docWidth / docHeight; // decimal ratio of original width/height
newWidth = width;
newHeight = ((1.0 * width) / docRatio); // decimal calc
if (newHeight > height) {
newWidth = docRatio * height; // decimal calc
newHeight = height;
}
// resize the image using a good conversion method while keeping the pixel resolution
// and the aspect ratio the same
app.activeDocument.resizeImage(newWidth, newHeight, resolution, ResampleMethod.BICUBIC);
app.preferences.rulerUnits = oldPref; // restore old prefs
isCancelled = false; // if get here, definitely executed
return false; // no error
}
I do not use the standard fit image myself as I use my own scripts with a simplified fit image embeded within.
While I agree it is more correct to strip the " px" from the width and height using .value once math is used on the variables containing the width and height "www px" and "hhh px" javascript strips the " px" so the end results are the same either way. The answer to your question however is Yes I did add .value