Thinkbox Software 製品
ブログ

テキスト注釈の合成

書き方:

textInfo = Draft.AnnotationInfo()     # 注釈情報初期化
textImage = Draft.Image.CreateAnnotation( “My ball!!!”, textInfo ) # 注釈画像作成
img.CompositeWithAnchor(textImage, Draft.Anchor.South , Draft.CompositeOperator.OverCompositeOp )          # 合成

※合成に関しては「二つの画像の合成」にて提示した3つの方法が利用できます。
Composite , CompositeWithAnchor , CompositeWithPositionAndAnchor
※コメントに2バイト文字は利用できません。

 

パラメータ:

PointSize :文字のポイントサイズを指定
FontType :type.xmlファイルに含まれる任意のフォントまたは指定されたフォントファイルが指定可能
例えば textInfo.FontType = ‘Times-New-Roman-Bold-Italic’ # フォント名指定
or:  textInfo.FontType = r’C:\Windows\Fonts\msmincho.ttf’ # フォントファイル名指定
Padding :文字の間隔を指定 1.0を指定しPointSizeがデフォルトの場合、32ピクセル開きます
Color  :文字色を色名称もしくは Draft.ColorRGBA(0.5、0.0、0.0、1.0)値は0.0~1.0の間で指定可能
BackgroundColor:背景の色をColorと同様に指定
ShadowColor :文字陰影色をColorと同様に指定
DrawShadow :文字陰影の表示 ture or false を指定

デフォルト値

PointSize:  32
FontType:  SourceSansPro-Regular
Padding:  0.0
Color:  white
BackgroundColor:  transparent
DrawShadow:  false   {
ShadowColor:  black

記述例:

画像に”My ball!!!”の文字を合成します
# -*- coding: UTF-8 -*-
import Draft   # DRAFTのAPIのインポート

img = Draft.Image.ReadFromFile( r’c:\test\ball.jpg’ )   # 元の画像を読込み
textInfo = Draft.AnnotationInfo()     # 注釈情報初期化
textInfo.PointSize = 64       # ポイントサイズを指定
textInfo.FontType = ‘Times-New-Roman-Bold-Italic’   # フォントを指定
textInfo.Color = Draft.ColorRGBA( 0.5, 0.0, 0.0, 1.0)   # 文字色を指定
textInfo.DrawShadow = True      # 文字陰影を設定
textImage = Draft.Image.CreateAnnotation( “My ball!!!”, textInfo ) # 注釈画像作成
img.CompositeWithAnchor(textImage, Draft.Anchor.South , Draft.CompositeOperator.OverCompositeOp )          # 合成
img.WriteToFile( r’c:\test\ball (annotated).jpg’ )   # 画像を保存