예제 #1
0
 def __init__(self, material):
     self.material = material
     if material == Material.STRAW:
         self.art = AsciiArt(straw_str)
     if material == Material.STICK:
         self.art = AsciiArt(stick_str)
     if material == Material.BRICK:
         self.art = AsciiArt(brick_str)
예제 #2
0
def test_image_info(test_image_path, capsys):
    # GIVEN a PIL Image object
    # WHEN the image_info method is called on the PIL Image object.
    # THEN the width and height of the image will be printed
    img = Image.open(test_image_path)
    a = AsciiArt(test_image_path)
    a.image_info()
    captured = capsys.readouterr()
    assert captured.out == f'Image size: {img.size[0]} x {img.size[1]}\n'
예제 #3
0
def test_brightness_to_char(test_image_path, brightness, brightness_range,
                            inverse, char):
    # GIVEN a brightness and a brightness_range
    # WHEN the brightness_to_char method is called
    # THEN a ascii_char will be returned as maped by the function according to it's
    #   relative brightness in the brightness in the range
    a = AsciiArt(test_image_path)
    a.ascii_chars = '012345'
    a.inverse = inverse
    assert a.brightness_to_char(brightness, brightness_range) == char
예제 #4
0
    def frames_to_ascii(self):
        """
        Converts the image frames extracted from the video file into ascii art images.
        """
        # File path where the image frames were saved
        image_frames_path = glob.glob(os.path.join(os.getcwd(), 'results',
                                                   'image-frame', '*.jpg'),
                                      recursive=True)

        # Converts each image into an ascii art image and saves the ascii image file over the original image frame.
        for i in image_frames_path:
            converted_image = ImageConfig(i)
            image_pixel_matrix = converted_image.get_pixel_matrix()
            ascii_art_image = AsciiArt(image_pixel_matrix)
            ascii_art_image.save_art_image(converted_image.get_new_width(),
                                           converted_image.get_new_height(), i)
예제 #5
0
 def huff_and_puff(self, house=None):
     wind = AsciiArt(wind_str)
     result = self.art.concat(wind, padding=3).concat(wind)
     if house != None:
         result = result.concat(house.art, padding=3)
         if house.material != Material.BRICK:
             house.destroy()
     return result
예제 #6
0
 def say(self, message):
     result = ""
     if len(message) > 0:
         message_lines = [
             message[i:i + self.art.width]
             for i in range(0, len(message), self.art.width)
         ]
         w = min(self.art.width, len(message))
         result += " " + "-" * (w + 2) + "\n"
         for m in message_lines:
             if len(m) < w:
                 m += ' ' * (w - len(m))
             result += "| " + m + " |" + "\n"
         result += " " + "-" * (w + 2) + "\n"
         result += " " * (w / 2) + "|" + "\n"
     result += str(self.art)
     return AsciiArt(result)
예제 #7
0
def test_scale_image(test_image_path, dest_width, dest_height, scale):
    # GIVEN a dest_width and dest_height
    # WHEN the scale_image method is called
    # THEN the scale factor will be returned to fit the image on the destination medium
    a = AsciiArt(test_image_path)
    assert a.scale_image(dest_width, dest_height) == scale
예제 #8
0
def test_construct_AsciiArt_class(test_image_path):
    # GIVEN a path to an image
    # WHEN the AsciiArt class is instantiated with the image path as an argument
    # THEN an AsciiArt object will be created
    a = AsciiArt(test_image_path)
    assert type(a).__name__ is 'AsciiArt'
예제 #9
0
 def __init__(self, art_str):
     self.art = AsciiArt(art_str)
예제 #10
0
 def destroy(self):
     self.art = AsciiArt(rubble_str)