Font are getting inconsistent in batch operations.

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: xbytor, DavideBarranca, Paul MR

prashantgangurde
Posts: 2
Joined: Sat Jan 21, 2017 4:46 am

Font are getting inconsistent in batch operations.

Postby prashantgangurde » Sat Jan 21, 2017 4:58 am

Hi All,

I am having below operations in my photoshop script:
1. reading folder having multiple images (reading images one by one).
2. Adding text layer to image with specific font. (each image uses different font which is kept in array)
3. saving the image and closing the same.
4. repeat this operation for each image.

while doing this i am getting incosistancy in the font sizes for the images, the font size is increased very high for some images. I am not able to figure out what I am missing in this?
Please help me in this.

attaching sample images output and photoshop script for the reference.
========================================================
var outputFolderPath = "E:\\photoshopAutoImages\\out";
var inputFolderPath = "E:\\photoshopAutoImages\\inputImages";
app.displayDialogs = DialogModes.NO;
//var doc = open(new File("E:\\photoshopAutoImages\\3.jpg"));
var fontName = "Vani";
var thumbnailName = "aloo gobi";
var artLayerRef = null;
var fontSize = 80;
var rectangleLength = 0;
var rectangleHeight = 0;
var yPosition =50;

var fontNameArray = new Array("Plump", "LeviReBrushed", "Basica", "Friday13", "Myriad Pro","GoodGirl","Arial","November","Velocity","Blacksword","Ravie","GROBOLD", "Vani", "ObelixPro", "Molot");
var fontArraySize = new Array(80, 80, 110, 90, 80, 80, 80, 80, 80, 100, 75, 80, 90, 80, 80);
var rectangleClearance = new Array(8, 3, 30, 6, 5, 8, 8, 8, 8, 8, 7, 5, -4, -20, 8);
run();
function run(){
var inputFolder = new Folder(inputFolderPath);
var inputFiles = inputFolder.getFiles("*.jpg");
for(index in inputFiles)
{
// open the file
var fileToOpen = new File(inputFiles[index]);
open(fileToOpen);
$.sleep(1000);
try{
makeThumbnail(fontNameArray[index], fontArraySize[index], thumbnailName, yPosition, rectangleClearance[index], false);
}catch(e){

alert ("EXCEPTION->"+e);
// app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
// open(fileToOpen);
// $.sleep(1000);
// makeThumbnail(fontNameArray[index], fontArraySize[index], thumbnailName, yPosition, rectangleClearance[index], true);
$.sleep(1000);
}
$.writeln("============ Completed the process ============");
}



function makeThumbnail(fontName, fontSize, thumbName, yposition, rectClearance, makeStripFlag){
if(makeStripFlag == false){
activeDocument.changeMode(ChangeMode.RGB);
}
// changeResolution();
//$.sleep(1000);
enterNameToImage(thumbName, fontName, fontSize);
$.sleep(1000);
addStroke();
$.sleep(1000);
if(makeStripFlag){
createRectangle(rectClearance);
$.sleep(1000);
changeLayerPosition();
}
saveFile(thumbName +" "+fontName);
$.sleep(1000);
}

function changeLayerPosition(){
activeDocument.activeLayer.move(artLayerRef, ElementPlacement.PLACEAFTER);
app.activeDocument.selection.deselect();
}
function enterNameToImage(thumbnailName, fontName, fontSize){
try{
app.displayDialogs = DialogModes.NO;
artLayerRef = app.activeDocument.artLayers.add()
// Specify that the layer is a text layer
artLayerRef.kind = LayerKind.TEXT
artLayerRef.textItem.kind = TextType.POINTTEXT
//This section defines the color of the hello world text
var textColor = new SolidColor();
textColor.cmyk.cyan = 0;
textColor.cmyk.magenta =0;
textColor.cmyk.yellow = 0;
textColor.cmyk.black = 0;

//Get a reference to the text item so that we can add the text and format it a bit
textItemRef = artLayerRef.textItem
textItemRef.font = fontName;
textItemRef.contents =thumbnailName;
textItemRef.color = textColor;
textItemRef.language = Language.SPANISH;
textItemRef.size =new UnitValue(fontSize, "px");
$.sleep(500);
textItemRef.position = new Array(20, yPosition+fontSize);
activeDocument.activeLayer.name = "Text";
activeDocument.activeLayer.textItem.justification = Justification.LEFT;
$.sleep(500);
var layer = activeDocument.activeLayer; //Grab the currently selected layer
//Calculate length and width based on the rectangular bounds of the selected layer
var textItem = layer.textItem;
textItem.kind = TextType.PARAGRAPHTEXT

var length = layer.bounds[2]-layer.bounds[0]; //Grab the length
var width = layer.bounds[3]-layer.bounds[1]; //Grab the width

app.activeDocument.selection.deselect();
rectangleLength = parseInt(textItem.width, 10) + 20;
rectangleHeight = parseInt(textItem.height, 10);
/* if(layer.kind == LayerKind.TEXT){
layer.textItem.font = fontName;
layer.textItem.size = new UnitValue(fontSize, "px");
}*/
$.writeln("=======================================");
$.writeln("FONT NAME->"+fontName);
$.writeln("Rectangle Length->"+rectangleLength);
$.writeln("Rectangle Width->"+rectangleHeight);
$.writeln("=======================================");
$.sleep(1000);
}catch(e){

alert ("EXCEPTION->"+e);
// app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

}
function cTID(s){
return app.charIDToTypeID(s);
}
function sTID(s){
return app.stringIDToTypeID(s);
}

function changeResolution(){
var idImgS = charIDToTypeID( "ImgS" );
var desc5 = new ActionDescriptor();
var idWdth = charIDToTypeID( "Wdth" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idWdth, idPxl, 1280.000000 );
var idHght = charIDToTypeID( "Hght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idHght, idPxl, 720.000000 );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
desc5.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
executeAction( idImgS, desc5, DialogModes.NO );
}
function saveFile(filename){
var thistimestamp = Math.round(new Date().getTime() / 1000);
var saveFile = new File( outputFolderPath+"\\" +filename+thistimestamp)
var saveOptions = new JPEGSaveOptions();
saveOptions.embedColorProfile = true;
saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
saveOptions.matte = MatteType.NONE;
saveOptions.quality = 9;
app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);
$.sleep(500);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
$.sleep(500);
}

function addStroke(){
var desc39 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putProperty( cTID('Prpr'), cTID('Lefx') );
ref13.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc39.putReference( cTID('null'), ref13 );
var desc40 = new ActionDescriptor();
desc40.putUnitDouble( cTID('Scl '), cTID('#Prc'), 100.000000 );
var desc41 = new ActionDescriptor();
desc41.putBoolean( cTID('enab'), true );
desc41.putEnumerated( cTID('Styl'), cTID('FStl'), cTID('OutF') );
desc41.putEnumerated( cTID('PntT'), cTID('FrFl'), cTID('SClr') );
desc41.putEnumerated( cTID('Md '), cTID('BlnM'), cTID('Nrml') );
desc41.putUnitDouble( cTID('Opct'), cTID('#Prc'), 100.000000 );
desc41.putUnitDouble( cTID('Sz '), cTID('#Pxl'), 3.500000 );
var desc42 = new ActionDescriptor();
desc42.putDouble( cTID('Rd '), 0.000000 );
desc42.putDouble( cTID('Grn '), 0.000000 );
desc42.putDouble( cTID('Bl '), 0.000000 );
desc41.putObject( cTID('Clr '), cTID('RGBC'), desc42 );
desc40.putObject( cTID('FrFX'), cTID('FrFX'), desc41 );
desc39.putObject( cTID('T '), cTID('Lefx'), desc40 );
executeAction( cTID('setd'), desc39, DialogModes.NO );
app.activeDocument.selection.deselect();
}

function createRectangle(rectangleClearace){
var rectLayer = activeDocument.artLayers.add();
yPosition = yPosition + rectangleClearace;
var thirdCoord = yPosition + rectangleHeight;
$.writeln("First Co-ord->"+0+","+yPosition);
$.writeln("Second Co-ord->"+rectangleLength+","+yPosition);
$.writeln("Thrid Co-ord->"+rectangleLength+","+rectangleHeight);
$.writeln("Forth Co-ord->"+0+","+rectangleHeight);
activeDocument.selection.select([[0, yPosition], [rectangleLength, yPosition], [rectangleLength,thirdCoord], [0,thirdCoord]], SelectionType.REPLACE, 0, false);
//activeDocument.selection.stroke (Colour, 4, StrokeLocation.INSIDE,ColorBlendMode.NORMAL,100);
var solidColorRef = new SolidColor();
solidColorRef.cmyk.cyan = 75;
solidColorRef.cmyk.magenta =68;
solidColorRef.cmyk.yellow = 67;
solidColorRef.cmyk.black = 90;
// app.foregroundColor = solidColorRef;
var opc = Math.round(app.activeDocument.activeLayer.opacity)
//alert("Opacity Value-->"+opc)
app.activeDocument.activeLayer.opacity = opc -50;
app.activeDocument.selection.fill(solidColorRef);
app.activeDocument.selection.deselect();
}
======================================================
Attachments
aloo gobi GoodGirl1484959331.jpg
font size increased
aloo gobi GoodGirl1484959331.jpg (346.49 KiB) Viewed 1220 times
aloo gobi Basica1484959299.jpg
Normal font
aloo gobi Basica1484959299.jpg (157.28 KiB) Viewed 1220 times



User avatar
Jaroslav Bereza
Posts: 36
Joined: Tue Dec 27, 2016 7:22 pm
Contact:

Re: Font are getting inconsistent in batch operations.

Postby Jaroslav Bereza » Sat Jan 21, 2017 11:07 pm

What are
1) images size?
2) images DPI?
3) texts unit?
Magic Scripts for Photoshop

prashantgangurde
Posts: 2
Joined: Sat Jan 21, 2017 4:46 am

Re: Font are getting inconsistent in batch operations.

Postby prashantgangurde » Sat Jan 28, 2017 4:56 am

Thanks a lot Jarpslav for your reply,
please find the below details for images:
original image details before changing the size and adding text layer.
1. Image which behaves abnormally with font size after script execution:
a. image size -1125 * 900 px
b. dpi - 180 pixel/inch
c. text units - pixels
2. Image which behaves normally with font size after script execution:
a. image size - 600 * 413 px
b. dpi - 72 pixel/Inch
c. text units - pixels

for above images in the photoshop script I am changing their size to (1280 * 720) and adding text layer to it with different fonts (with size between 80 to 120). but for it is behaving very abnormally with font sizes. The font size is changing to 333.33 px for first image with font name as "GoodGirl". I am not able to figure out why it is creating like that.
attaching both fonts and images in the zip file.
Attachments
fontchanging.zip
(477.3 KiB) Downloaded 68 times

xbytor
Posts: 20
Joined: Thu Jan 01, 1970 12:00 am

Re: Font are getting inconsistent in batch operations.

Postby xbytor » Mon Jan 30, 2017 2:58 am

I think that the easiest thing to do would to be change the dpi to 72dpi (if needed), do your op, then revert back to the original dpi (if needed). There have been a host of font related errors over there years where this was the only solution.

Let us know if this works.

-X


Return to “Photoshop Scripting - General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest