Question

I have several images to watermark. Each images are different resolutions ans sizes. I am trying to resize the images to 300 x 225 and water mark with a text in the bottom of the resized image. Everything works fine except the water mark are not consistent in sizes. Originally higher resolution images have smaller watermarks and lower resolutions have very big watermarks. I am adding text layer to the resized images as watermarks. I think i am missing some setting when adding the text layer. Please help.

    ResizeImage ();
    CreateWatermark( );

    function ResizeImage()
    {
      var MedWidth =  UnitValue(300,"px"); 
      var MedHeight = UnitValue(225,"px");
      activeDocument.resizeImage(MedWidth,null,null,ResampleMethod.BICUBIC);
      activeDocument.resizeCanvas(MedWidth,MedHeight,AnchorPosition.MIDDLECENTER);
}



function CreateWatermark( )
{
  var fface = "Arial-BoldMT"
  var size =6



  // Add a new layer in the new document
  var currentDoc = activeDocument;
  var artLayerRef = app.activeDocument.artLayers.add()

  artLayerRef.kind = LayerKind.TEXT


  textColor = new SolidColor();
  textColor.rgb.red = 245;
  textColor.rgb.green = 7;
  textColor.rgb.blue = 7;


  textItemRef = artLayerRef.textItem
  textItemRef.font = fface;
  textItemRef.contents = 'picture provided by landlord';
  textItemRef.color = textColor;
  textItemRef.size = size
  textItemRef.position = new Array(currentDoc.width-200, currentDoc.height-10)
  activeDocument.activeLayer.name = "watermark";
  activeDocument.activeLayer.textItem.justification = Justification.LEFT;
}
Was it helpful?

Solution

Most likely, you're setting the size of the TextItem in points, and the PPI of your images varies. Points are a unit of measurement that depend on the PPI of the document. This is so text of a given size in points is the same physical size (in inches) when printed.

There are two ways you can get your text layer's size to be consistent:

  • Use a consistent PPI.

    The third argument to Document#resizeImage is the resolution (PPI). Try setting it to 96 (the conventional DPI of computer displays).

    activeDocument.resizeImage(MedWidth, null, 96, ResampleMethod.BICUBIC);
    

    With a consistent DPI, your font size should also be consistent.

  • Set the text layer's size in pixels rather than points.

    TextItem#size can be set to a UnitValue, which allows you to specify the unit of measurement to be used. Pixels are always pixels and do not depend on the document's PPI.

    textItemRef.size = new UnitValue(15, 'px');
    

Either should work; you only need to use one. I'd lean toward the first option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top