Page 1 of 1

Photoshop CS2 resize without resampling bug

Posted: Thu Jun 02, 2005 7:11 am
by MickM
I came across this bug while trying to answer a question on the Adobe forum. It is important to be clear that this bug is related to resizing WITHOUT RESAMPLING only.

Problem: It is not possible in Photoshop CS2 to resize an image without resampling and specifying a new document size at the same time. This was possible in CS so that existing code will break in CS2.

This is the same as using the Image Size dialog without Resample Image unchecked and changing the document size (the lower part of the dialog box). The usual reason for doing this is to set the document size for printing. It does not have any effect on the pixel size of the image and changing units to pixels does not have any effect here (pixels are not a unit option in the Document Size part of the dialog box).

Note that it is still possible to change the resolution without resampling but it is not possible if even one dimension is supplied

The following VB.NET code works in CS but generates an error in CS2
Code: Select allDim app As New Photoshop.Application
Dim doc As Photoshop.Document
Dim docWidth As Double = 4
Dim docRes As Double
app.Preferences.RulerUnits = Photoshop.PsUnits.psInches

doc = app.ActiveDocument
doc.ResizeImage(docWidth, , , Photoshop.PsResampleMethod.psNoResampling)

Solution: The workaround is to manually calculate the resolution that the document should have at the particular desired size.

Workaround in VB.NET:

Code: Select allDim app As New Photoshop.Application
Dim doc As Photoshop.Document
Dim originalRulerUnits As Photoshop.PsUnits       
Dim docWidth, desiredWidth As Double
Dim docRes As Double
Dim resizeFactor As Double

originalRulerUnits = app.Preferences.RulerUnits
app.Preferences.RulerUnits = Photoshop.PsUnits.psInches
desiredWidth = 4 ' new width in inches

If app.Documents.Count > 0 Then

     doc = app.ActiveDocument
     docRes = doc.Resolution
      'get doc width in inches
     docWidth = doc.Width()
      'resizeFactor is used to calculate new resolution
     resizeFactor = docWidth / desiredWidth
     'resize without resampling using new resolution
     doc.ResizeImage(, , resizeFactor * docRes, Photoshop.PsResampleMethod.psNoResampling)

End If

Catch ex As Exception


End Try

'Restore unit setting
app.Preferences.RulerUnits = originalRulerUnits

Photoshop CS2 resize without resampling bug

Posted: Sun Jun 05, 2005 11:08 pm
by Larry Ligon

I get the same error in Visual Basic 6.


Photoshop CS2 resize without resampling bug

Posted: Mon Jun 06, 2005 12:08 am
by Larry Ligon
Here's how to do this in JavaScript:

Code: Select allvar strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;

//Calculate the new width in points and use the script listener code
var pointsPerInch = 72 ;
//Set the new width to 4 inches converted to points
var newWidthInPoints = 4 * pointsPerInch ;

var id18 = charIDToTypeID( "ImgS" );
    var desc3 = new ActionDescriptor();
    var id19 = charIDToTypeID( "Wdth" );
    var id20 = charIDToTypeID( "#Rlt" );
    desc3.putUnitDouble( id19, id20, newWidthInPoints  );
executeAction( id18, desc3, DialogModes.NO );


app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;

Hope this helps,