예제 #1
0
def slice00():
    req_width = 595
    req_height = 35
    euro_img = Image(filename = IMAGE_PATH + "euros.png")
    euro_img = resize_to_height(euro_img, req_height)

    mask_img = new_blank_png(width=req_width, height=req_height, 
        color=Color('rgb(150,150,150)'))
    background_img = new_blank_png(width=req_width, 
        height=req_height, color=Color('rgb(44,128,64)'))
   
    euro_img.composite_channel(channel='all_channels', image=mask_img, 
        operator='copy_opacity')
    background_img.composite(euro_img, 0, 0)

    return background_img
예제 #2
0
from wand.image import Image
from wand.color import Color

img1 = Image(filename='baseColorWand.jpg')
img2 = Image(filename='baseTexture.jpg')
img1.composite_channel(channel='undefined',
                       image=img2,
                       operator='blend',
                       left=0,
                       top=0)
img1.save(filename='.\\test\\undefined_blend.jpg')
img1.composite_channel(channel='rgb_channels',
                       image=img2,
                       operator='blend',
                       left=0,
                       top=0)
img1.save(filename='.\\test\\rgb_channels_blend.jpg')
img1.composite_channel(channel='all_channels',
                       image=img2,
                       operator='undefined',
                       left=0,
                       top=0)
img1.save(filename='.\\test\\all_channels_undefined.jpg')
# img = Image(filename='102.jpg')
# baseImage = Image(width=560, height=840, background=Color('red'))
# baseImage.save(filename='.\\test\\basecolor.jpg')
# img.composite_channel(channel='undefined', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\undefined_blend.jpg')
# img.composite_channel(channel='alpha', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\alpha_blend.jpg')
# img.composite_channel(channel='composite_channels', image=baseImage, operator='blend', left=0, top=0)
예제 #3
0
def generate(count):
    # ---------------get three colors-------------------------------
    colorString = random.choice(result)
    color = []
    for i in colorString:
        color += [int(i)]
    # for i in range(len(color)):
    #     color[i] = math.floor(color[i]/255*65535)
    color1 = color[0:3]
    color2 = color[3:6]
    color3 = color[6:9]
    # --------------------------------------------------------------

    # ----------get the base layer texture--------------------------
    Scenes = pathwalk('./SceneData')

    randomScene = random.choice(Scenes)
    randomScene = randomScene[0] + '/' + randomScene[1]
    print(randomScene)
    randomSceneImage = Image(filename=randomScene)

    widthRange = randomSceneImage.size[0] - 100
    heightRange = randomSceneImage.size[1] - 32

    randomSceneImage.crop(left=random.randint(0, widthRange),
                          top=random.randint(0, heightRange),
                          width=100,
                          height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----

    baseImage = Image(
        width=100,
        height=32,
        background=Color('rgb(' + str(color1[0]) + ',' + str(color1[1]) + ',' +
                         str(color1[2]) + ')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined',
                                image=randomSceneImage,
                                operator='blend',
                                left=0,
                                top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = randomWords()
    fonts = pathwalk('./fonts/font_en/')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
    draw.font = randomFont

    tmp = int(math.floor(abs(random.gauss(0, 1)) * 6))
    if random.randint(1, 2) == 1:
        rotateX = random.randint(0, tmp)
    else:
        rotateX = random.randint(360 - tmp, 360)

    draw.rotate(rotateX)
    # --------------------------------------------------------------
    # --------get suitable FontPointSize----------------------------
    draw.font_size = initialPointsize
    metric = draw.get_font_metrics(image=baseImage, text=word)

    while metric.text_width > 100 or metric.text_height > 36:
        initialPointsize -= 5
        draw.font_size = initialPointsize
        metric = draw.get_font_metrics(image=baseImage, text=word)
    # --------------------------------------------------------------

    # ----------italic----------------------------------------------
    if random.random() > 0.5:
        draw.font_style = 'italic'
    # --------------------------------------------------------------

    # ----------underline-------------------------------------------
    if random.random() > 0.5:
        draw.text_decoration = 'underline'
    # --------------------------------------------------------------

    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(int(addx)), y=abs(int(addy)), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb(' + str(color3[0]) + ',' +
                                  str(color3[1]) + ',' + str(color3[2]) + ')')
        draw.stroke_width = math.ceil(initialPointsize / 10) - 1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb(' + str(color2[0]) + ',' + str(color2[1]) +
                            ',' + str(color2[2]) + ')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------

    print(word)
    baseImage.save(filename='./photo_en/' + str(count + 1) + '_' + word +
                   '.jpg')
예제 #4
0
    # 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)

    # make text with gradient
    textimg.composite_channel(channel, gradient, 'in')

    # curve it
    textimg.distort('arc', [120], True)

    # add shadow
    shadowimg = textimg.clone()
    shadowimg.background_color = Color('black')
    shadow(shadowimg, 100, 2, 4, 4)

    # composite all
    canvas = Image(width=textimg.width, height=textimg.height,
                   background=Color('white'))
    canvas.composite(shadowimg, 0, 0)
    canvas.composite(textimg, 0, 0)
    canvas.save(filename='sample39.png')
예제 #5
0
    randomScene = randomScene[0] + randomScene[1]
    # print(randomScene)
    randomSceneImage = Image(filename=randomScene)

    widthRange = randomSceneImage.size[0] - 100
    heightRange = randomSceneImage.size[1] - 32

    randomSceneImage.crop(left=random.randint(0, widthRange), top=random.randint(0, heightRange), width=100, height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----
    baseImage = Image(width=100, height=32, background=Color('rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined', image=randomSceneImage, operator='blend', left=0, top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = python2access.randomWords()
    fonts = pathwalk('.\\googleFonts\\')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
    draw.font = randomFont
예제 #6
0
파일: test.py 프로젝트: dailuo/ImageMagick
from wand.image import Image
from wand.color import Color

img1 = Image(filename='baseColorWand.jpg')
img2 = Image(filename='baseTexture.jpg')
img1.composite_channel(channel='undefined', image=img2, operator='blend', left=0, top=0)
img1.save(filename='.\\test\\undefined_blend.jpg')
img1.composite_channel(channel='rgb_channels', image=img2, operator='blend', left=0, top=0)
img1.save(filename='.\\test\\rgb_channels_blend.jpg')
img1.composite_channel(channel='all_channels', image=img2, operator='undefined', left=0, top=0)
img1.save(filename='.\\test\\all_channels_undefined.jpg')
# img = Image(filename='102.jpg')
# baseImage = Image(width=560, height=840, background=Color('red'))
# baseImage.save(filename='.\\test\\basecolor.jpg')
# img.composite_channel(channel='undefined', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\undefined_blend.jpg')
# img.composite_channel(channel='alpha', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\alpha_blend.jpg')
# img.composite_channel(channel='composite_channels', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\composite_channels_blend.jpg')
# img.composite_channel(channel='rgb_channels', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\rgb_channels_blend.jpg')
# img.composite_channel(channel='true_alpha', image=baseImage, operator='blend', left=0, top=0)
# img.save(filename='.\\test\\true_alpha_blend.jpg')
예제 #7
0
shadowcolor = 'rgb(0,0,75%)'


# const(don't change)
def_ch = 'default_channels'

# make CLUT table for metalic coloring
clut_width = 1
clut_height = 1000
clutimg = Image(filename='gradient:{0}-black'.format(maincolor),
                width=clut_width, height=clut_height)
clutimg.gamma(1.0)
with Image(filename='gradient:', width=clut_width, height=clut_height) as tmp:
    tmp.gamma(0.9)
    tmp.function('sinusoid', [2.25, 0.0, 0.5, 0.5])
    clutimg.composite_channel(def_ch, tmp, 'overlay')
clutimg.rotate(90)


# make text image
inputimg = None
with Drawing() as draw:
    draw.font = font
    draw.font_size = font_size
    (w, h) = calcSuitableImagesize(draw, text)
    inputimg = Image(width=w, height=h, background=Color('white'))
    draw.fill_color = Color('black')
    draw.gravity = 'center'
    draw.text(0, 0, text)
    draw(inputimg)
blur(inputimg, 0, 5)
예제 #8
0
                          width=100,
                          height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----
    baseImage = Image(
        width=100,
        height=32,
        background=Color('rgb(' + str(color1[0]) + ',' + str(color1[1]) + ',' +
                         str(color1[2]) + ')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined',
                                image=randomSceneImage,
                                operator='blend',
                                left=0,
                                top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = python2access_cn.randomWords_cn()
    fonts = pathwalk('.\\fonts\\font_cn\\')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
예제 #9
0

with Drawing() as draw:
    text = ' I M  Examples '
    draw.font = 'Anaconda-Regular'
    draw.font_size = 72
    (w, h) = calcSuitableImagesize(draw, text)

    # make text image
    textimg = Image(width=w, height=h, background=Color('black'))
    draw.gravity = 'center'
    draw.fill_color = Color('dodgerblue')
    draw.text(0, 0, text)
    draw(textimg)
    textimg.border(Color('black'), 30, 30)

    # make shadow image
    shadowimg = textimg.clone()
    blur(shadowimg, 0, 25)
    shadowimg.level(black=0.0, gamma=1.0, white=0.5)

    # composite all
    canvas = Image(width=shadowimg.width, height=shadowimg.height)
    canvas.composite(shadowimg, 0, 0)
    canvas.composite_channel('default_channels', textimg, 'screen')
    canvas.save(filename='sample40.png')

    shadowimg.destroy()
    textimg.destroy()
    canvas.destroy()
예제 #10
0
def slice02():
    # Resize image to height (but do not change the aspect ratio)
    #
    req_width = 595
    req_height = 486
    baby_img = Image(filename=IMAGE_PATH + "baby_cc_sh.png")
    baby_img = resize_to_height(baby_img, req_height)

    # For this particular image, reflect image along vertical
    # axis to have face directed towards right of page.
    #
    baby_img.flop()

    # Create the the gradient transition that will later be used
    # in the opacity mask.
    #
    gradient_blob = create_gradient_blob(req_height, 75, gradient([
        (1.0, (0x00, 0x00, 0x00), (0xFF, 0xFF, 0xFF)), # top
    ]))
    gradient_img = Image(blob=gradient_blob)
    gradient_img.rotate(90.0)

    # When building the opacity mask, must start with an image
    # having a solid colour (i.e., begin as a "matte" image).
    # Without this, the later "composite_channel" operations
    # will simply not work.
    #
    opacity_mask = new_blank_png(req_width, req_height, color=Color('white'))
    left_field = new_blank_png(230, req_height, Color('white'))
    right_field = new_blank_png(290, req_height, Color('black'))
    opacity_mask.composite(left_field, 0, 0)
    opacity_mask.composite(right_field, 230+75, 0)
    opacity_mask.composite(gradient_img, 230, 0)

    # Now take the resized baby image and have it fade to the right
    # (in order to blend with later operations).
    #
    face_img = new_blank_png(req_width, req_height)
    face_img.composite(baby_img, 0, 0)
    face_img.composite_channel(channel='all_channels', image=opacity_mask, 
        operator='copy_opacity')

    # Bring in the illustrative image that will eventually be blended in
    # with the child's face.
    #
    accent_img = Image(filename = IMAGE_PATH + "funky_illustration.png")
    accent_img = resize_to_percent(accent_img, 60)
    accent_img = resize_to_height(accent_img, 486)

    cropped_img = accent_img.clone()
    cropped_img.crop(top=0, left=275, width=340, height=486)
    screen_img = new_blank_png(340, 486, color=Color('rgb(150,150,150)'))
    cropped_img.composite_channel(channel='all_channels', image=screen_img, 
        operator='screen')

    accent_img = new_blank_png(req_width, req_height)
    accent_img.composite_channel(channel='all_channels', image=cropped_img, 
        operator='over', left=255, top=0)
    accent_img.gaussian_blur(3.0, 1.0)

    opacity_mask = new_blank_png(req_width, req_height, color=Color('white'))
    left_field = new_blank_png(260, req_height, Color('black'))
    right_field = new_blank_png(290, req_height, Color('white'))
    opacity_mask.composite(left_field, 0, 0)
    opacity_mask.composite(right_field, 260+75, 0)
    gradient_img.rotate(180)
    opacity_mask.composite(gradient_img, 260, 0)
    accent_img.composite_channel(channel='all_channels', image=opacity_mask, 
        operator='copy_opacity')

    # Now layer the accent image with the child's face
    #
    accent_img.composite_channel(channel='all_channels', image=face_img,
        operator='over')
    full_slice = accent_img 

    # Finally, add the text field on the right of the image.
    #
    text_field = new_blank_png(212, req_height, color=Color('rgb(190,30,45)'))
    text_field_mask = new_blank_png(212, req_height, color=Color('rgb(220,220,220)'))
    text_field.composite_channel(channel='all_channels', image=text_field_mask, 
        operator='copy_opacity')
    full_slice.composite(text_field, 384, 0)

    draw = Drawing()
    draw.font = FONT_BOLD
    draw.font_size = 24
    draw.fill_color = Color('white')
    draw.text(395, 175, "Liam Mulcahy")
    draw.font = FONT_REGULAR
    draw.font_size = 20
    draw.text(395, 200, "Eyes to the Future")
    draw.font = FONT_ITALIC
    draw.font_size = 20
    draw.text(395, 250, 'How dreams of')
    draw.text(395, 275, 'future enterprise')
    draw.text(395, 300, 'success are')
    draw.text(395, 325, 'starting while still')
    draw.text(395, 350, 'in nappies!')
    draw(full_slice)
   
    # Done.
    # 
    return full_slice
def generate(count):
    # ---------------get three colors-------------------------------
    colorString = random.choice(result)
    color = []
    for i in colorString:
        color += [int(i)]
    # for i in range(len(color)):
    #     color[i] = math.floor(color[i]/255*65535)
    color1 = color[0:3]
    color2 = color[3:6]
    color3 = color[6:9]
    # --------------------------------------------------------------

    # ----------get the base layer texture--------------------------
    Scenes = pathwalk('./SceneData')

    randomScene = random.choice(Scenes)
    randomScene = randomScene[0] + '/' + randomScene[1]
    print(randomScene)
    randomSceneImage = Image(filename=randomScene)

    widthRange = randomSceneImage.size[0] - 100
    heightRange = randomSceneImage.size[1] - 32

    randomSceneImage.crop(left=random.randint(0, widthRange), top=random.randint(0, heightRange), width=100, height=32)
    # randomSceneImage.save(filename='.\\photoWand\\'+str(j+1) + '_texture.jpg')
    # --------------------------------------------------------------

    # ----------create the base layer, base texture +base color-----

    baseImage = Image(width=100, height=32, background=Color('rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')'))

    # print('base_color = ' + 'rgb('+str(color1[0])+','+str(color1[1])+','+str(color1[2])+')')
    baseImage.composite_channel(channel='undefined', image=randomSceneImage, operator='blend', left=0, top=0)
    baseImage.gaussian_blur(4, 10)
    baseImage.resolution = (96, 96)
    # --------------------------------------------------------------

    # -----generate font--------------------------------------------
    word = randomWords()
    fonts = pathwalk('./fonts/font_en/')
    randomFont = random.choice(fonts)
    randomFont = randomFont[0] + randomFont[1]

    initialPointsize = 45

    draw = Drawing()
    draw.font = randomFont

    tmp = int(math.floor(abs(random.gauss(0, 1))*6))
    if random.randint(1, 2) == 1:
        rotateX = random.randint(0, tmp)
    else:
        rotateX = random.randint(360-tmp, 360)

    draw.rotate(rotateX)
    # --------------------------------------------------------------
    # --------get suitable FontPointSize----------------------------
    draw.font_size = initialPointsize
    metric = draw.get_font_metrics(image=baseImage, text=word)

    while metric.text_width > 100 or metric.text_height > 36:
        initialPointsize -= 5
        draw.font_size = initialPointsize
        metric = draw.get_font_metrics(image=baseImage, text=word)
    # --------------------------------------------------------------

    # ----------italic----------------------------------------------
    if random.random() > 0.5:
        draw.font_style = 'italic'
    # --------------------------------------------------------------

    # ----------underline-------------------------------------------
    if random.random() > 0.5:
        draw.text_decoration = 'underline'
    # --------------------------------------------------------------

    # ----------gravity---------------------------------------------
    draw.gravity = 'center'
    # --------------------------------------------------------------

    # --------------shadow/border-----------------------------------
    if random.random() < 0.5:
        # shadow
        addx = math.ceil(random.gauss(0, 2))
        addy = math.ceil(random.gauss(0, 2))
        draw.fill_color = Color('black')
        draw.text(x=abs(int(addx)), y=abs(int(addy)), body=word)

    else:
        # border
        draw.stroke_color = Color('rgb('+str(color3[0])+','+str(color3[1])+','+str(color3[2])+')')
        draw.stroke_width = math.ceil(initialPointsize/10)-1
    # --------------------------------------------------------------

    # ----------print word------------------------------------------
    draw.fill_color = Color('rgb('+str(color2[0])+','+str(color2[1])+','+str(color2[2])+')')
    draw.text(x=0, y=0, body=word)
    draw.draw(baseImage)
    # --------------------------------------------------------------

    # ------------gray----------------------------------------------
    baseImage.colorspace = 'gray'
    # --------------------------------------------------------------

    print(word)
    baseImage.save(filename='./photo_en/'+str(count+1)+'_'+word+'.jpg')