Photoshop CS2 resize without resampling bug

Bugs and Anomalies in Photoshop excluding Scripting and Actions

Moderators: xbytor, DavideBarranca, Paul MR

MickM

Photoshop CS2 resize without resampling bug

Postby MickM » Thu Jun 02, 2005 7:11 am

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 all
Dim 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 all
Dim 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

Try
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

      MessageBox.Show(ex.Message)

End Try

'Restore unit setting
app.Preferences.RulerUnits = originalRulerUnits



Larry Ligon

Photoshop CS2 resize without resampling bug

Postby Larry Ligon » Sun Jun 05, 2005 11:08 pm

MickM,

I get the same error in Visual Basic 6.

Larry

Larry Ligon

Photoshop CS2 resize without resampling bug

Postby Larry Ligon » Mon Jun 06, 2005 12:08 am

Here's how to do this in JavaScript:

Code: Select all
var 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 );

alert("Finished");

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


Hope this helps,
Larry


Return to “Photoshop Bugs and Anomalies”

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest