Copy link to clipboard
Copied
I've been using Photoshop's Trim and Resize image and I realized that it always deletes unwanted pixels of my .psd document.
What can I do to have a more accurate Trim / Resize on my documents? I believe the cause of this is due to Resize.
The script is very simple:
doc = app.activeDocument;
// trim
doc.trim(TrimType.TRANSPARENT);
// ========== set units to pixels ==========//
var oldPrefs = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
DocTrimmedWidth = doc.width;
DocTrimmedHeight = doc.height;
// resize algorithm
if (DocTrimmedHeight > DocTrimmedWidth) {
doc.resizeImage(undefined, UnitValue(1024, "px"),72, ResampleMethod.BICUBIC, 100);
}
else {
doc.resizeImage(UnitValue(1024, "px"), undefined, 72, ResampleMethod.BICUBIC, 100);
}
doc.activeLayer.applyOffset(0,512, OffsetUndefinedAreas.WRAPAROUND);
I tried different kinds of ResampleMethods to no avail. Here's the .psd I'm using it on:
ImproperResize.psd - Google Drive
There are always transparents pixels appearing on the .psd. What can I do about this problem?
https://i.imgur.com/TZc36yG.png
Try using this plugin for the resize
Copy link to clipboard
Copied
Try using this plugin for the resize
Copy link to clipboard
Copied
You can call this plugin in the script using the following function
)
function c3c_resize(w, h, sharp, use_contrast)
{
try {
if (sharp == undefined) sharp = 0;
if (use_contrast == undefined) use_contrast = false;
var old_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var doc = app.activeDocument;
var w0 = Number(doc.width.value);
var h0 = Number(doc.height.value);
while (w > w0 || h > h0)
{
doc.resizeImage(UnitValue(4*w0,"px"), UnitValue(4*h0,"px"), doc.resolution, ResampleMethod.NEARESTNEIGHBOR);
w0 = Number(doc.width.value);
h0 = Number(doc.height.value);
}
app.preferences.rulerUnits = old_units;
var d = new ActionDescriptor();
d.putInteger( charIDToTypeID( "Wdth" ), w );
d.putInteger( charIDToTypeID( "Hght" ), h );
d.putBoolean( charIDToTypeID( "cC3P" ), true );
d.putBoolean( charIDToTypeID( "cC3F" ), false );
d.putEnumerated( charIDToTypeID( "uc3S" ), charIDToTypeID( "tc3U" ), charIDToTypeID( "uc30" ) );
if (use_contrast == true)
d.putEnumerated( charIDToTypeID( "mc3S" ), charIDToTypeID( "tc3M" ), charIDToTypeID( "rc31" ) );
else
d.putEnumerated( charIDToTypeID( "mc3S" ), charIDToTypeID( "tc3M" ), charIDToTypeID( "rc30" ) );
d.putInteger( charIDToTypeID( "pC3S" ), sharp );
d.putInteger( charIDToTypeID( "pC3W" ), w );
d.putInteger( charIDToTypeID( "pC3H" ), h );
executeAction( stringIDToTypeID( "5f3d6843-d895-44c2-bbb7-b71ca0cb8c01" ), d, DialogModes.NO );
return true;
}
catch (e) { alert(e); return false; }
}
Copy link to clipboard
Copied
Great, thanks for the help r-bin. I'll try this out in an hour when I'm back home.
Copy link to clipboard
Copied
Please change the line in the function
d.putBoolean( charIDToTypeID( "cC3P" ), true );
to
d.putBoolean( charIDToTypeID( "cC3P" ), false );
This guarantees the exact final dimensions W and H that you set.
This parameter tries to keep the proportions fitting on only the width
Copy link to clipboard
Copied
It works great, thanks Much appreciated!
Copy link to clipboard
Copied
I tried to use it on mac
with photoshop cs6 cc cc2014 does not work?
Copy link to clipboard
Copied
It's strange. On a mac I can not say anything. Write to the author.