Friday, 24 February 2017

Photoshop script for continuous Facebook cover and profile images

Facebook cover images are 851 x 315 pixels.
Profile images are 180 x 180.

If you copy the Facebook page and measure the cover image it's 851 x 315 but the profile is 160 x 160. It's also 336 high to the bottom of the profile.

So, start with an image 851 *18/16 = 957  x  336*18/16 = 378

Crop out the profile 180 x 180
Restore the original
Resize to 851 width
Crop out top 851 x 315

or copy the script below into a text file called Rolands_FBtrick.jsx and save it with the Photoshop scripts
in

C:\Program Files (x86)\Adobe\Adobe Photoshop CS2\Presets\Scripts

Next time Photoshop is started it will be available to run


It's not quite perfect but unless you're aligning grooves on a gramophone record it'll probably be good enough.

This darkening gradient is added to the cover image by the Facebook system
I'm saving that for another day

To get the profile to match the cover, add this gradient as the top layer, scale so it covers the whole image and set blend mode to darken.

=======copy script after here=======

/*
CS2 Script to produce Cover & Profile images for Facebook from an original which must be 957 x 378 pixels or it will be resized. Output files default to the source folder and _Profile & _Cover are appended to the names. Jpeg quality is 60. Edit as required below
If you want to match the gradient on the profile image, set it as the top layer and select it before running the script.
*/
var NewW=957; NewH=378; FBW=851; FBH=315; //don't have to be global but they're easier to edit here

function SaveForWeb(Suffix) {
  if (stopflag){return false;}
  try {
      Piccy.path;
    }
  catch(err) {
      alert('Please save the image and try again');
      stopflag=true;
      return false;
  }
var JpegQuality = 60; // <<<<=========== edit jpeg quality between 0 & 100

if (Suffix=='Profile') {
      Destn=Folder(app.activeDocument.path).selectDlg("Choose folder to save the files and click OK. Default is the original folder\n\nJpeg quality is "+JpegQuality);
    }
if (Destn==null){
  stopflag=true;
  return false;
}

//-----------------Use 2nd line below if you always want to save to the original folder and avoid the dialog
Filename=File(Destn + "/" + Piccy.name.slice(0, Piccy.name.length-4) + "_" + Suffix + ".jpg");
//  Filename=File(Piccy.path + "/" + Piccy.name.slice(0, Piccy.name.length-4) + "_" + Suffix + ".jpg");
//-----------------
  if(Filename.exists){
    var Warning=Filename.toString();
    Warning= Warning.slice(3, Warning.length);
    if(!confirm(Warning + " already exists\n\nDo you want to replace it?")){
      stopflag=true;
      return false;
    }
    Filename.remove();
  }
  var sfwOptions = new ExportOptionsSaveForWeb();
    sfwOptions.format = SaveDocumentType.JPEG;
    sfwOptions.includeProfile = true;
    sfwOptions.interlaced = 0;
    sfwOptions.optimized = true;
    sfwOptions.quality = JpegQuality;
  Piccy.exportDocument(Filename, ExportType.SAVEFORWEB, sfwOptions);
}

function main(){
  if (documents.length==0){alert('No image open'); return false;}
  Piccy=app.activeDocument;
  var savedState = Piccy.activeHistoryState; //save original
  var userPrefUnits = app.preferences.rulerUnits; // in case units aren't pixels
  if (userPrefUnits !== Units.PIXELS){app.preferences.rulerUnits = Units.PIXELS;} //change to pixels & reinstate at the end
  if (Piccy.width !== NewW & Piccy.height !== NewH){Piccy.resizeImage(NewW,NewH,null,ResampleMethod.BICUBICSHARPER);}
// bounds are left, top, right, bottom -ScriptListener order is Top, Left, Btom, Rght
//var bounds = [23, 198, 203, 378]; // values from ScriptListener
  var bounds = [22, 199, 202, 379];
  Piccy.crop(bounds);
  SaveForWeb("Profile");
  Piccy.activeHistoryState = savedState;
  app.activeDocument.activeLayer.visible = false;
  Piccy.resizeImage(FBW,null,null,ResampleMethod.BICUBICSHARPER);
  bounds = [0, 0, 851, 315];
  Piccy.crop(bounds);
  SaveForWeb("Cover");
  if(userPrefUnits !== Units.PIXELS){app.preferences.rulerUnits = userPrefUnits;}
  Piccy.activeHistoryState = savedState;
}
var stopflag=false;
var Piccy;
var Destn;
main();


No comments:

Post a Comment

Note: only a member of this blog may post a comment.