Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Resizing document without losing colored pixels

Participant ,
Feb 04, 2018 Feb 04, 2018

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

TOPICS
Actions and scripting
886
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Feb 04, 2018 Feb 04, 2018

Try using this plugin for the resize

C3C Image Size – Telegraph

Translate
Adobe
People's Champ ,
Feb 04, 2018 Feb 04, 2018

Try using this plugin for the resize

C3C Image Size – Telegraph

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 05, 2018 Feb 05, 2018

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; }

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 05, 2018 Feb 05, 2018

Great, thanks for the help r-bin. I'll try this out in an hour when I'm back home.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 05, 2018 Feb 05, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 05, 2018 Feb 05, 2018
LATEST

It works great, thanks Much appreciated!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 05, 2018 Feb 05, 2018

I tried to use it on mac

with photoshop  cs6 cc cc2014 does not work?

Schermata 2018-02-05 alle 10.48.48.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Feb 05, 2018 Feb 05, 2018

It's strange. On a mac I can not say anything. Write to the author.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines