vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Programming Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=188)
-   -   Photoshop Script to Change Matte Color (https://vborg.vbsupport.ru/showthread.php?t=135662)

drews 01-05-2007 10:00 PM

Photoshop Script to Change Matte Color
 
I created a Photoshop script that will open all the PSDs in a folder and Save To Web as .gif using a matte color you specify in hex out to a folder of your choice.

You need to specify the hex color in the code around line 52, just put in the value without the preceding "#" sign. Copy and paste the code to into a new text document and save it as <somename>.jsx .

Unfortunately, it doesn't do folder traversing so if you have multiple folders it will be necessary to do each folder individually. I created this script especially for use with the vBulletin PSDs for easy matting. It has been tested in Adobe Photoshop CS2.

Code below... let me know how you like it.

HTML Code:

// enable double clicking from the Macintosh Finder or the Windows Explorer
#target photoshop

///////////////////////////
//      SET-UP          //
///////////////////////////

// A list of file extensions to skip, keep them lower case
    gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );

// Pops open a dialog for the user to choose the folder of documents to process
    var inputFolder = Folder.selectDialog("Select a folder of documents to process");

// Pops open a dialog for the user to set the output folder
    var outputFolder = Folder.selectDialog("Select a folder for the output files");

///////////////////////////
//        MAIN          //
///////////////////////////

// Open Folder of Images   
    var numFiles = OpenFolder();
   
///////////////////////////
//      FUNCTIONS      //
///////////////////////////

main();

function main() {
    if (app.documents.length <= 0)
    {
        alert("You must have a document open to Save For Web");
        return;
    }
   
    try
    {
        for(var i = 0; i < numFiles; i++)
        {
            //alert("Save To Web");
            RunSaveForWeb();
            //alert("Closing");
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
        }
    }
    catch (error)
    {
        if (error.number != 8007) // Don't report user cancelled errors.
            alert (error); //  + ":" + error.line);
    }
}

function RunSaveForWeb()
{
    //Define SaveForWeb Options
    var matteColorColor = new RGBColor();
    matteColorColor.hexValue = "000000";
    var sfwOptions = new ExportOptionsSaveForWeb();
    sfwOptions.format = SaveDocumentType.COMPUSERVEGIF;
    sfwOptions.includeProfile = false;
    sfwOptions.colors = 256;
    sfwOptions.matteColor = matteColorColor;
    sfwOptions.interlaced = 0;
     
    //Save for Web
    docPath = outputFolder;
    docName = activeDocument.name;
    var temp = new Array();
    temp = docName.split('.');
    sfwJpgFile = new File(docPath + "\\" + temp[0] + ".gif");
    activeDocument.exportDocument(sfwJpgFile, ExportType.SAVEFORWEB, sfwOptions);
}

// Given the a Folder of files, open them
function OpenFolder()
{
    var filesOpened = 0;
    var fileList = inputFolder.getFiles();
    for (var i = 0; i < fileList.length; i++)
    {
        // Make sure all the files in the folder are compatible with PS
        if (fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese(fileList[i], gFilesToSkip))
        {
            open(fileList[i]);
            filesOpened++;
      }
    }
  return filesOpened;
}

// given a file name and a list of extensions
// determine if this file is in the list of extensions

function IsFileOneOfThese( inFileName, inArrayOfFileExtensions )
{
    var lastDot = inFileName.toString().lastIndexOf(".");
    if (lastDot == -1)
    {
        return false;
    }
    var strLength = inFileName.toString().length;
    var extension = inFileName.toString().substr(lastDot + 1, strLength - lastDot);
    extension = extension.toLowerCase();
    for (var i = 0; i < inArrayOfFileExtensions.length; i++ )
    {
        if ( extension == inArrayOfFileExtensions[i] )
        {
            return true;
        }
    }
    return false;
}


kether1 02-27-2007 01:29 AM

What a great idea!

-Kether

StepOnFrog 06-25-2008 10:42 PM

This is exactly what I've wanted for ages.

The problem for many users is that the standard vBulletin images (buttons, smilies, status icons, etc.) are all matted to a white background (the vBulletin standard out-of-box style). When it comes to changing your style to a darker colour (black, or blue, etc.) all the images tend to show a fine white border around them, that is most off-putting.

What you have done with this article is provided users a way of keeping their standard vBulletin images (I actually prefer them to the crap that's out there...), without having to keep the standard vBulletin style (which isn't the best in the world).

The only problem users have now is getting a copy of Photoshop CS2 +.

If I could buy you a pint, I would.

Thx

:-D
step

domainmagick 02-04-2009 10:45 PM

very nice - thanks! gonna try this out now, was just googling for this exact thing :)


All times are GMT. The time now is 10:41 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01080 seconds
  • Memory Usage 1,731KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete