5 Replies Latest reply on Sep 13, 2011 2:15 PM by bsnyder175

    convert rgb to color image?

    bsnyder175 Level 1

      I have an excel doc with around 1,000 color names and their respective RGB values.  Is it possible to create a script that will read a csv and save each row as a 500px x 500px solid-color document?


      I'm just looking for a quick way to convert a text-list of colors into actual jpg color files with the file name being column A (the color name) and the image representing the solid rgb color.  Any ideas?


      Screen Shot 2011-09-13 at 1.01.39 PM.png

        • 1. Re: convert rgb to color image?
          Paul Riggott Level 6

          This should be close....



          #target photoshop
          var inputFile = File.openDialog("Please select CSV file.","CSV File:*.csv"); 
          var outputFolder = Folder.selectDialog( "Please select output folder");
          var datFile=[];
          var line = inputFile.readln();
          if(line.length > 5) datFile.push(line);
          var FillColour = new SolidColor;
          for(var a in datFile){
          var line = datFile[a].split(',');
          var ColourName = line[0].toString().replace(/^ +| +$/g,'');
          FillColour.rgb.red = line[1].toString().replace(/^ +| +$/g,'');
          FillColour.rgb.green = line[2].toString().replace(/^ +| +$/g,'');
          FillColour.rgb.blue = line[3].toString().replace(/^ +| +$/g,'');
          app.backgroundColor = FillColour;
          app.documents.add(new UnitValue( 500, 'px' ), new UnitValue( 500, 'px' ), 72, ColourName, NewDocumentMode.RGB, DocumentFill.BACKGROUNDCOLOR);
          var saveFile = File(outputFolder +"/"+ColourName+".jpg");
          function SaveForWeb(saveFile,jpegQuality) {
          var sfwOptions = new ExportOptionsSaveForWeb(); 
             sfwOptions.format = SaveDocumentType.JPEG; 
             sfwOptions.includeProfile = false; 
             sfwOptions.interlaced = 0; 
             sfwOptions.optimized = true; 
             sfwOptions.quality = jpegQuality;
          activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
          • 2. Re: convert rgb to color image?
            bsnyder175 Level 1

            Paul to the rescue once again!  From initial tests, the script is working great.  I'll have run it on the entire list and see how it goes.


            Thanks so much, Paul.

            • 3. Re: convert rgb to color image?
              bsnyder175 Level 1

              Hey Paul,


              Right now, the filename handles spaces (i.e. "Pink Cadillac") by inserting dashes instead (Pink-Cadillac).  Is it possible to have the file name retain the spaces found in the csv, or is that just how spaces are handled?

              • 4. Re: convert rgb to color image?
                Paul Riggott Level 6

                Hi Bret the - are inserted because of the way you have Save For Web setup it's the Filename Compatability screen, UNIX will be ticked and should be unticked.

                Go to Save For Web and Devices

                Select the menu...


                Select Edit Output Settings

                And keep on going next till you get this screen...



                Hope this helps.

                1 person found this helpful
                • 5. Re: convert rgb to color image?
                  bsnyder175 Level 1

                  Aha.  You're right; that did the trick.