fitting text into the box

前端 未结 2 622
长发绾君心
长发绾君心 2021-02-09 07:24

on my website i allow users to create pictures with line of text they specify drawn on the picture

currently i use for that imagemagick convert - i specify svg template

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-09 07:57

    solved by abandoning svg and doing everything with imagemagick convert and mvg template

    here's the simplified script example in case anyone's pursuing something similar

    script is putting an image and a title on the canvas. title is created with separate convert command, saved as temporary file and then put onto the canvas

    #!/bin/sh
    
    TEMPLATE="
    push graphic-context
    viewbox 0 0 600 600 
    affine 1 0 0 1 0.0 0.0
    push graphic-context
    fill 'rgb(0,0,0)'
    rectangle 0,0 600,600
    pop graphic-context
    push graphic-context
    image Over 38,38 338,338 '%s' 
    pop graphic-context
    push graphic-context
    image Over 36,400 529,55 '%s' 
    pop graphic-context
    pop graphic-context
    ";
    
    #1. creating label fitting specified proportions 
    #2. converting mvg template to jpeg image (and trimming it in process) 
    #3. removing temp file with label
    
    convert -size 529x55 -background black -family "Times New Roman" -gravity center -fill white label:"$2" "tmp/$1title.jpg" && printf "$TEMPLATE"  "images/$1.jpg" "tmp/$1title.jpg"  | convert mvg:- -trim +repage -bordercolor black -border 36  "images/$1converted.jpg" && rm "tmp/$1title.jpg"
    
    #script parameters: $1 is image id, $2 is title text
    

提交回复
热议问题