CS4: Fit Image Problem

R
Posted By
randykepple
Nov 18, 2008
Views
1220
Replies
15
Status
Closed
Recently had a very bizarre issue that just happened. Not sure why, but it won’t go away.

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?

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

J
jjmack
Dec 2, 2008
The is cause by the Adobe records Script Plug-ins in actions. When a script is recorded in and action the script file full path is recorded in the action. If you install a new version of Photoshop and uninstall the old version the action you recorded in the old version of Photoshop will fail with that message for the previous versions script path do no linger exist. Prior to CS3 Fit Image was a compiled plug-in when compiled plug-ins are recorded in actions no path is recorded just the plug-in.
J
jjmack
Dec 2, 2008
Photoshop records sizes depending on how the ruler units are currently set. However the Fit Image Dialog just supports pixels so fit image should always record pixels I believe.
J
jjmack
Dec 2, 2008
I don’t have CS4 however when I look act an action recorded in CS3 that uses the Fit image Script all I see recorded is two lines JavaScript File: "the full CS3 script path and name" second line message: "Fit Image settings" I don’t see any values
R
randykepple
Dec 2, 2008
JJ…I appreciate you taking the time to comment on this issue. However, why comment on a CS4 issue if you don’t even have it installed?

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! 🙂
J
jjmack
Dec 2, 2008
The reason I commented was I knew what the problem is. "Fit Image" Prior the Photoshop CS3 was a Compiled Photoshop Plug-in. When recorded is an action it was recorded as step "Fit Image" and two settings Width xxx Pixels and Height yyy pixels. In Version CS3 Adobe added Plug-in support to Photoshop Scripting and changed "Fit Image" coded it in Javascript. However IMO Adobe failed to make and approbate change to the Action recorder. Instead of recording the ‘Fit Image’ Plug-in script as a Plug-in it recorded it as a normal use of a script which includes the full path of the script file. Old actions that were recorded prior to CS3 that used the compiled "Fit Image" were recorded as a plug-in step these will continue to work in CS3 and CS4 because the "Fit Image" plug-in script registries itself as the Automate Plug-in Fit Image during Photoshop’s start up process. Myself I will not have the problem because I deleted the Adobe Fit Image Script because it had a bug. I fixed the bug and added code to use Bicibic Smoother when up-sizing and Bicubic Sharper when down-sizing. I installed My in mt Photoshop Script Tree which does not change with each release of Photoshop. Do you understand why I answered now.
R
randykepple
Dec 2, 2008
JJ…that makes perfect sense! When you take the time to explain (and I appreciate that you did) I do understand.

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!
J
jjmack
Dec 2, 2008
The problem come down to the fact the the way scripts are recorded in actions the full path of the script is recorded. If you un-install CS3 its script directory will be deleted so the script is gone CS4 script is in a different directory.

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
J
jjmack
Dec 2, 2008
The other code change I made was in the image resize Adobe Always use intopolation method "BICUBIC" I changed the in my version From 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);

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); }
R
randykepple
Dec 2, 2008
This does not solve MY specific issue, but it’s GREAT information and I appreciate you posting it here. I wish I could write and understand Javascripting like that. Very cool stuff! 🙂
PR
Paul_R
Dec 2, 2008
I wonder if you have changed these lines yet?
docWidth = (1.0 * app.activeDocument.width * resolution) / 72.0; docHeight = (1.0 * app.activeDocument.height * resolution) / 72.0; to
docWidth = (1.0 * app.activeDocument.width.value * resolution) / 72.0; docHeight = (1.0 * app.activeDocument.height.value * resolution) / 72.0;
R
randykepple
Dec 2, 2008
Paul,

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?
R
randykepple
Dec 2, 2008
Here is the section of the javascript dealing with the resize:

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
}
PR
Paul_R
Dec 2, 2008
The changes I mentioned should be added to the changes that were made by jjmack.

I do not use the standard fit image myself as I use my own scripts with a simplified fit image embeded within.
J
jjmack
Dec 3, 2008
Paul

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

docWidth = (1.0 * app.activeDocument.width.value * resolution) / 72.0; docHeight = (1.0 * app.activeDocument.height.value * resolution) / 72.0;
PZ
Ping Zheng
Dec 29, 2008
I track the code in Fit Image script and find the unit displayed in Action have nothing to do with Fit Image script, throughout the script, it calculated in px.
Because there is one line : "app.preferences.rulerUnits = Units.PIXELS;" May be it is an action issue, I will dig it

How to Improve Photoshop Performance

Learn how to optimize Photoshop for maximum speed, troubleshoot common issues, and keep your projects organized so that you can work faster than ever before!

Related Discussion Topics

Nice and short text about related topics in discussion sections