Exemple #1
0
 def test_imagesize(self):
     with Drawing() as d:
         text = 'check'
         d.font = 'Arial'
         d.font_size = 36
         size = calcSuitableImagesize(d, text)
         print('calcSuitableImagesize: ', size)
         self.assertTrue(size[0] > 0 and size[1] > 0)
Exemple #2
0
# original imagemagick command:
#  convert -font Times-Bold -pointsize 64 \
#                     -background none  label:"Colorful Arc" \
#          \( +clone -sparse-color Barycentric '0,%h blue %w,0 red' \
#             \) -compose In -composite \
#          -virtual-pixel transparent -distort arc 120 \
#          \( +clone -background black -shadow 100x2+4+4 \
#             \) +swap -background white -compose over -layers merge +repage \
#          colorful_arc.jpg


text = 'Colorful Arc'
with Drawing() as draw:
    draw.font = 'Times-Bold'
    draw.font_size = 64
    (w, h) = calcSuitableImagesize(draw, text)

    # make gradient image(blue -> red)
    gradient = Image(width=w, height=h, background=Color('black'))
    channel = 'default_channels'  # see CHANNELS in 'wand/image.py'
    #                                              x  y  R    G    B    A
    sparsecolor(gradient, channel, 'barycentric', [0, h, 0.0, 0.0, 1.0, 1.0,
                                                   w, 0, 1.0, 0.0, 0.0, 1.0])

    # make text image
    textimg = Image(width=w, height=h)
    draw.gravity = 'center'
    draw.fill_color = Color('white')
    draw.text(0, 0, text)
    draw(textimg)
#!/usr/bin/env python

from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
from wandplus.textutil import calcSuitableImagesize

# http://www.imagemagick.org/Usage/text/
# original imagemagick command:
# echo -n "Vertical" | sed 's/./&@/g; s/@$//' | tr '@' '\012' |\
#     convert -background lightblue -fill blue -font Ravie -pointsize 24 \
#             -gravity center    label:@-   label_vertical.gif

with Drawing() as draw:
    text = 'Vertical'
    text = '\n'.join(list(text))  # insert \n between each char
    draw.font = 'Ravie'
    draw.font_size = 24
    draw.gravity = 'center'
    (w, h) = calcSuitableImagesize(draw, text, multiline=True)
    with Image(width=w, height=h, background=Color('lightblue')) as img:
        draw.fill_color = Color('blue')
        draw.text(0, 0, text)
        draw(img)
        img.save(filename='sample10.png')