Here is a draft of a poster script that I use in another application. The issue referring to layers after resizing is present. I get the same error after merging two layers that are not the background layer.
Code: Alles auswählen
' PhotoLine script by Russell Cottrell.
' Adds faux matting and a title to an image.
' Optimized for printing.
' Images should have a resolution of at least 300 ppi but will work with any.
Option Explicit
Dim pl, doc, size, printSize, res, aLayer
Dim mountWidth, mountHeight, matSpace
Dim matPly, printEdge, ratio, surroundWidth
Dim matColor, mountColor, fontColor
Dim topColorP, sideColorP, bottomColorP, topColorM, sideColorM, bottomColorM
Dim ww, hh, left, top, x0, x1, x2, x3, y0, y1, y2, y3, i
Dim fontDict, paragraphDict, fontSize, textLayer, range
Set pl = CreateObject("PhotoLine.Application")
Set doc = pl.ActiveDocument
size = doc.Size
printSize = size
res = doc.Resolution
fontSize = size(1) * 0.05
matPly = 4 * (3/256)
matSpace = 1/4
printEdge = 1/150
'set the mount size as a ratio of the linear dimensions of the mount to the print:
ratio = 1.6
surroundWidth = Sqr((size(0)/res) * (size(1)/res)) * ((ratio - 1) / 2)
mountWidth = size(0)/res + surroundWidth*2
mountHeight = size(1)/res + surroundWidth*2
'extra space at the bottom; would use 0.1 if not adding a title:
mountHeight = mountHeight + (surroundWidth - matPly - matSpace - printEdge)*0.2
mountWidth = Round(mountWidth * res)
mountHeight = Round(mountHeight * res)
matSpace = Round(matSpace * res)
matPly = Round(matPly * res)
printEdge = Round(printEdge * res)
surroundWidth = Round(surroundWidth * res)
Set matColor = CreateObject("PhotoLine.Color")
matColor.Model = 1
matColor.Values = Array(240/255, 240/255, 240/255)
Set topColorP = CreateObject("PhotoLine.Color")
topColorP.Model = 1
topColorP.Values = Array(240/255, 240/255, 240/255)
Set sideColorP = CreateObject("PhotoLine.Color")
sideColorP.Model = 1
sideColorP.Values = Array(200/255, 200/255, 200/255)
Set bottomColorP = CreateObject("PhotoLine.Color")
bottomColorP.Model = 1
bottomColorP.Values = Array(160/255, 160/255, 160/255)
Set topColorM = CreateObject("PhotoLine.Color")
topColorM.Model = 1
topColorM.Values = Array(120/255, 120/255, 120/255)
Set sideColorM = CreateObject("PhotoLine.Color")
sideColorM.Model = 1
sideColorM.Values = Array(160/255, 160/255, 160/255)
Set bottomColorM = CreateObject("PhotoLine.Color")
bottomColorM.Model = 1
bottomColorM.Values = Array(200/255, 200/255, 200/255)
Set mountColor = CreateObject("PhotoLine.Color")
mountColor.Model = 1
mountColor.Values = Array(255/255, 255/255, 255/255)
Set fontColor = CreateObject("PhotoLine.Color")
fontColor.Model = 1
fontColor.Values = Array(51/255, 51/255, 51/255)
'PRINT EDGE
ww = size(0) + printEdge*2
hh = size(1) + printEdge*2
doc.DoOperation "Resize", "Size", Array(ww, hh), "Horizontal", 2, "Vertical", 2, "Color", sideColorP
size = doc.Size
Set aLayer = doc.ActiveLayer 'have to do this after resizing
x0 = 0
x1 = size(0)
x2 = size(0) - printEdge
x3 = printEdge
y0 = 0
y1 = 0
y2 = printEdge
y3 = printEdge
FillSelection aLayer, topColorP
x0 = printEdge
x1 = size(0) - printEdge
x2 = size(0)
x3 = 0
y0 = size(1) - printEdge
y1 = size(1) - printEdge
y2 = size(1)
y3 = size(1)
FillSelection aLayer, bottomColorP
'MAT SPACE
ww = size(0) + matSpace*2
hh = size(1) + matSpace*2
doc.DoOperation "Resize", "Size", Array(ww, hh), "Horizontal", 2, "Vertical", 2, "Color", MountColor
size = doc.Size
Set aLayer = doc.ActiveLayer
'MAT BEVEL
ww = size(0) + matPly*2
hh = size(1) + matPly*2
doc.DoOperation "Resize", "Size", Array(ww, hh), "Horizontal", 2, "Vertical", 2, "Color", sideColorM
size = doc.Size
Set aLayer = doc.ActiveLayer
x0 = 0
x1 = size(0)
x2 = size(0) - matPly
x3 = matPly
y0 = 0
y1 = 0
y2 = matPly
y3 = matPly
FillSelection aLayer, topColorM
x0 = matPly
x1 = size(0) - matPly
x2 = size(0)
x3 = 0
y0 = size(1) - matPly
y1 = size(1) - matPly
y2 = size(1)
y3 = size(1)
FillSelection aLayer, bottomColorM
'MOUNT SIZE
ww = mountWidth
hh = mountHeight
left = (mountWidth - size(0)) / 2
top = surroundWidth - matPly - matSpace - printEdge
doc.DoOperation "Resize", "Size", Array(ww, hh), "Position", Array(left, top), "Color", matColor
size = doc.Size
Set aLayer = doc.ActiveLayer
'TITLE
Set fontDict = CreateObject("PhotoLine.Dictionary")
fontDict.Add "FamilyName", "Palatino Linotype", "Size", fontSize
Set paragraphDict = CreateObject("PhotoLine.Dictionary")
paragraphDict.Add "Alignment", 2
Set textLayer = CreateObject("PhotoLine.Text")
'customize the title text; would like to read it from a text file:
textLayer.Text = Mid(doc.Path, InStrRev(doc.Path, "\") + 1)
range = Array(0, textLayer.TextLength)
textLayer.Origin = Array(0, surroundWidth + printSize(1) + matPly + matSpace + printEdge + fontSize*1.5)
textLayer.Size = Array(size(0), fontSize) 'is there a way to get the size from fontDict?
textLayer.SetAttribute range, "Color", fontColor
textLayer.SetAttribute range, "Font", fontDict
textLayer.SetAttribute range, "Paragraph", paragraphDict
aLayer.Parent.Insert textLayer, aLayer
Sub FillSelection(layer, color)
Dim vector
Set vector = CreateObject("PhotoLine.Vector")
vector.FillColor(0) = color
vector.LineColor(0) = Array(0, 0, 0, 0)
vector.InsertPoints 0, 0, array(x0, y0, x1, y1, x2, y2, x3, y3, x0, y0)
layer.Parent.Insert vector, layer
doc.Merge Array(layer, vector)
End Sub
If the image could be lifted to a layer off the background and moved, it would make it easy to adjust its vertical position.
I like to apply an emboss filter to the text; this would require converting the layer type from text to RGB, and then an emboss operation; could this be done?
Side note: in the ScriptingVBScript document, the text for ParagraphAlignment and ParagraphRegister are reversed.