chilli-axe / mtg-photoshop-automation

Photoshop scripting to generate high-quality Magic card renders, inserting Scryfall data into Photoshop frame templates.
GNU General Public License v3.0
60 stars 39 forks source link

Text layers on some templates are `corrupted` #25

Closed CoffeeKing68 closed 3 years ago

CoffeeKing68 commented 3 years ago

Hi @ndepaola

Thanks for the hard work you have done here, I attempted to do the same thing a while back and failed miserably.

Anyways, I found an issue where I on the normal.psd, if I changed a textItem.size, it would not be the number I set it too. I found this Adobe Photoshop thread and it solved the issue for me.

The problem is with textlayers that have been transformed. You have to remake them to solve the issue.

You can use this code to see if the layers are "corrupted":

var filePath = File($.fileName).parent.parent.fsName;

function makeLogFile() {
  // make logfile
  var logFolder = new Folder(filePath + "/logs");
  logFolder.create();

  var logFile = new File(filePath + "/logs/" + "log.log");
  logFile.open("w", "TEXT");
  logFile.close();
}

makeLogFile();

function log(s) {
  var logFile = new File(filePath + "/logs/" + "log.log");
  if (s === undefined) s = "";
  logFile.open("a", "TEXT");
  logFile.write(s + "\n");
  logFile.close();
}

function main() {
  var templates = [
    "normal",
    "normal-boxtopper",
    "womensday"
  ];
  for (var i = 0; i < templates.length; i++) {
    doesTemplateContainTransformedTextlayers(templates[i]);
  }
}

function logFontSizes(template) {
  log(template);
  log()
  var templateLocation = filePath + "/templates/";
  var templatePath = templateLocation + template + ".psd";

  app.open(new File(templatePath));
  var docRef = app.activeDocument;
  var textAndIcons = docRef.layers.getByName("Text and Icons");

  var cardNameLayer = textAndIcons.layers.getByName("Card Name");
  var manaCostLayer = textAndIcons.layers.getByName("Mana Cost");
  var typelineLayer = textAndIcons.layers.getByName("Typeline");

  // cardNameLayer.textItem.contents = "Lmao";

  log(docRef.resolution);

  var layers = {
    "nameLayer": cardNameLayer,
    "manaCostLayer": manaCostLayer,
    "typelineLayer": typelineLayer
  };

  for (var key in layers) {
    log(key);
    var layer = layers[key];
    logLayerTextSize(layer);
    layer.textItem.size = layer.textItem.size;
    log("after setting size to itself");
    logLayerTextSize(layer);
  }
}

function doesTemplateContainTransformedTextlayers(template) {
  // bug discussed here
  // https://feedback.photoshop.com/conversations/photoshop/photoshop-cs6-wrong-fontsize-displaying-when-selecting-multiple-text-layers/5f5f45374b561a3d423cde77
  // still happens on my CC 2017 install

  log(template);

  var templateLocation = filePath + "/templates/";
  var templatePath = templateLocation + template + ".psd";

  app.open(new File(templatePath));
  var docRef = app.activeDocument;

  var textAndIcons = docRef.layers.getByName("Text and Icons");
  var legal = docRef.layers.getByName("Legal");

  var textGroupLayers = [textAndIcons, legal];

  var allLayersArePassing = true;
  for (var i = 0; i < textGroupLayers.length; i++) {
    var layerGroup = textGroupLayers[i];
    log("=== " + layerGroup.name);

    for (var j = 0; j < layerGroup.artLayers.length; j++) {
      var layer = layerGroup.artLayers[j];
      if (layer.kind == LayerKind.TEXT) {
        var failed = isTextLayerTransformed(layer);
        if (failed) {
          allLayersArePassing = false;
          log("FAILED: " + layer.name);
          // } else {
          //   log("PASSED: " + layer.name);
        }
      }
    }
  }
  log("allLayersPassing? " + allLayersArePassing);
  log();
}

function isTextLayerTransformed(textLayer) {
  var initialSize = textLayer.textItem.size;
  textLayer.textItem.size = initialSize;

  return initialSize != textLayer.textItem.size;
}

I've got some other improvements and fixes, but I need copies of the un-rasterized templates found on the g-drive. Do you still have them? It will make the automation way faster.

I've also managed to automate the womensday.psd template, it's just that I have modified the other functions too much, it would break the other templates' code (which I could fix with the un-rasterized templates).

Thanks for your hard work (writing formatText.jsx would have driven me insane!) CoffeeKing

ndepaola commented 3 years ago

hello! thanks for getting in touch

It's frustrating that text layers get corrupted like this yea - I've encountered the issue before and I wasn't able to find a solution other than deleting & recreating the text layer either.

The reason you're encountering this issue on my templates now is bc at the end of last year, I went through all of my templates and adjusted their physical sizes to 2.74 x 3.74 inches (inc. the print bleed edge you need for MPC) but I haven't gotten around to fixing their text boxes yet. So the versions of the scripts you see on here expect the starting font size to be 60-something pt which is obviously another issue.

I'm actually in the middle of rebuilding all of my templates from scratch to fix some issues I've noticed over the last year (legendary crown isn't very accurate, PT box is pixelated, name & title box bevels point the wrong way, etc.) and the new templates will have regenerated text layers. I'm waiting until I finish recreating all of my templates in this way before I release any of them - so far I've finished my normal, tf-front, tf-back, and znrexp templates, and also created mdfc-front and mdfc-back templates to eventually release too. Slowly going through and redoing all of the images on my drive w/ the new templates at the same time.

So when I release those templates I'll also be updating this repo w/ changes including: fixed font sizes to be correct for the 2.74 x 3.74 inch canvas size, a built in way of switching to other templates (e.g. masterpiece or znrexp) for some cards, support for automating mdfc's (and hopefully adventures but we'll see how that goes), and the script now correctly un-italicises specific words in flavour text where necessary (e.g. booster tutor). Also releasing an adjusted Beleren font where the asterisk has been replaced with the asterisk from MPlantin so cards with asterisks in their PT look correct (e.g. tarmogoyf)

I do have the vector source version of the new templates, but it's a titanic mess and I wouldn't feel comfortable releasing it, sorry! How the master template works & is laid out is all contained in my head as well so idk how much sense it'd make to another person without documentation.

Thank you for the kind words - writing formatText.jsx absolutely drove me insane - spent way too long staring at extracts from PS's script listener for that! PS script's interaction with text layers is frustratingly limited so that was the only way I could change the colours of specific characters in text layers.

CoffeeKing68 commented 3 years ago

Hi @ndepaola

Ok cool, do you have a discord or some place where we can talk more freely? I have lots of suggestions/ideas/code that could help.

Thanks CoffeeKing

ndepaola commented 3 years ago

absolutely! You can find an invite link on mpcautofill.com :)