Beispiel #1
0
 def test_full_process(self):
     here = os.path.abspath(os.path.dirname(__file__))
     image = os.path.join(here, 'image.jpg')
     brick = os.path.join(here, 'brick.png')
     legofy.main(image, brick, output='lego_image.png')
     expected = os.path.join(here, 'lego_image.png')
     self.assertTrue(os.path.exists(expected))
Beispiel #2
0
def lego(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    size = get_param(update, 50, 1, 100)
    if size is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension == ".webp" or ".png":
        stick = "convert " + path + filename + extension + " -background white -flatten " + path + filename + extension
        subprocess.run(stick, shell=True)
    legofy.main(image_path=path + filename + extension,
                output_path=path + filename + "-lego" + extension,
                size=size,
                palette_mode=None,
                dither=False)
    send_image(update, path, filename + "-lego", extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-lego" + extension)
Beispiel #3
0
def main(image, output, size, palette, dither):
    '''Legofy an image!'''
    legofy.main(image,
                output_path=output,
                size=size,
                palette_mode=palette,
                dither=dither)
Beispiel #4
0
 def test_bricks_parameter(self):
     self.create_tmpfile('.png')
     legofy.main(FLOWER_PATH, output_path=self.out_path, bricks=5)
     size5 = os.path.getsize(self.out_path)
     legofy.main(FLOWER_PATH, output_path=self.out_path, bricks=10)
     size10 = os.path.getsize(self.out_path)
     self.assertTrue(size5 > 0)
     self.assertTrue(size10 > size5)
Beispiel #5
0
    def test_legofy_image(self):
        '''Can we legofy a static image?'''
        self.create_tmpfile('.png')
        self.assertTrue(os.path.exists(FLOWER_PATH),
                        "Could not find image : {0}".format(FLOWER_PATH))

        legofy.main(FLOWER_PATH, output_path=self.out_path)
        self.assertTrue(os.path.getsize(self.out_path) > 0)
Beispiel #6
0
 def test_legofy_gif(self):
     '''Can we legofy a gif?'''
     self.create_tmpfile('.gif')
     gif_path = os.path.join(TEST_DIR, '..', 'legofy', 'assets', 'bacon.gif')
     self.assertTrue(os.path.exists(gif_path),
                     "Could not find image : {0}".format(gif_path))
     legofy.main(gif_path, output_path=self.out_path)
     self.assertTrue(os.path.getsize(self.out_path) > 0)
Beispiel #7
0
    def test_legofy_image(self):
        '''Can we legofy a static image?'''
        self.create_tmpfile('.png')
        self.assertTrue(os.path.exists(FLOWER_PATH),
                        "Could not find image : {0}".format(FLOWER_PATH))

        legofy.main(FLOWER_PATH, output_path=self.out_path)
        self.assertTrue(os.path.getsize(self.out_path) > 0)
Beispiel #8
0
    def test_legofy_image(self):
        '''Can we legofy a static image?'''
        self.create_tmpfile('.png')
        image_path = os.path.join(self.test_dir, '..', 'legofy', 'assets', 'flower.jpg')
        self.assertTrue(os.path.exists(image_path),
                        "Could not find image : {0}".format(image_path))

        legofy.main(image_path, output=self.out_path)
        self.assertTrue(os.path.getsize(self.out_path) > 0)
Beispiel #9
0
 def test_bricks_parameter(self):
     '''Can we specify the --brick parameter and is the file size
        proportional?'''
     self.create_tmpfile('.png')
     legofy.main(FLOWER_PATH, output_path=self.out_path, size=5)
     size5 = os.path.getsize(self.out_path)
     legofy.main(FLOWER_PATH, output_path=self.out_path, size=10)
     size10 = os.path.getsize(self.out_path)
     self.assertTrue(size5 > 0)
     self.assertTrue(size10 > size5)
Beispiel #10
0
 def test_legofy_palette(self):
     '''Can we use a palette?'''
     self.create_tmpfile('.png')
     self.assertTrue(os.path.exists(FLOWER_PATH),
                     "Could not find image : {0}".format(FLOWER_PATH))
     out = self.out_path
     legofy.main(FLOWER_PATH, output_path=out, palette_mode='solid')
     legofy.main(FLOWER_PATH, output_path=out, palette_mode='transparent')
     legofy.main(FLOWER_PATH, output_path=out, palette_mode='effects')
     legofy.main(FLOWER_PATH, output_path=out, palette_mode='mono')
     legofy.main(FLOWER_PATH, output_path=out, palette_mode='all')
     self.assertTrue(os.path.getsize(out) > 0)
Beispiel #11
0
    def convert_file(self):
        try:
            if self.chosenFile is not None:

                palette = self.colorPalette.get()

                if palette in LEGO_PALETTE and palette != 'none':
                    legofy.main(self.chosenFile.name, size=self.brickNumberScale.get(), palette_mode=palette)
                else:
                    legofy.main(self.chosenFile.name, size=self.brickNumberScale.get())

                tkmsg.showinfo("Success!", "Your image has been legofied!")
            else:
                tkmsg.showerror("File not found", "Please select a file before legofying")
        except Exception as e:
            tkmsg.showerror("Error", str(e))
Beispiel #12
0
def main(image, scale, brick, output):
    '''Main entry point'''
    if brick and output:
        legofy.main(image, scale, brick=brick, output=output)
    elif brick:
        legofy.main(image, scale, brick=brick)
    elif output:
        legofy.main(image, scale, output=output)
    else:
        legofy.main(image, scale)
Beispiel #13
0
    def convert_file(self):
        try:
            if self.chosenFile is not None:

                palette = self.colorPalette.get()

                if palette in LEGO_PALETTE and palette != 'none':
                    legofy.main(self.chosenFile.name,
                                size=self.brickNumberScale.get(),
                                palette_mode=palette)
                else:
                    legofy.main(self.chosenFile.name,
                                size=self.brickNumberScale.get())

                tkmsg.showinfo("Success!", "Your image has been legofied!")
            else:
                tkmsg.showerror("File not found",
                                "Please select a file before legofying")
        except Exception as e:
            tkmsg.showerror("Error", str(e))
Beispiel #14
0
def main(brick, image, output):
    if brick and output:
        legofy.main(image, brick=brick, output=output)
    if brick:
        legofy.main(image, brick=brick)
    if output:
        legofy.main(image, output=output)
Beispiel #15
0
def main(brick, image, output):
    if brick and output:
        legofy.main(image, brick=brick, output=output)
    if brick:
        legofy.main(image, brick=brick)
    if output:
        legofy.main(image, output=output)
Beispiel #16
0
def main(image, output, bricks, brick):
    '''Main entry point'''
    if output:
        if bricks:
            if brick:
                legofy.main(image,
                            output=output,
                            bricks=bricks,
                            brick_path=brick)
            else:
                legofy.main(image, output=output, bricks=bricks)
        elif brick:
            legofy.main(image, output=output, brick_path=brick)
        else:
            legofy.main(image, output=output)
    elif bricks:
        if brick:
            legofy.main(image, bricks=bricks, brick_path=brick)
        else:
            legofy.main(image, bricks=bricks)
    elif brick:
        legofy.main(image, brick_path=brick)
    else:
        legofy.main(image)
Beispiel #17
0
import legofy
import os

here = os.path.abspath(os.path.dirname(__file__))
# print(here)
# print(legofy)
legofy.main(os.path.join(here, 'image.jpg'), 30, os.path.join(here, 'brick.png'))
# legofy.main(image, brick=os.path.join(here, 'bricks', 'brick.png'))
Beispiel #18
0
import legofy
import os

here = os.path.abspath(os.path.dirname(__file__))
# print(here)
# print(legofy)
legofy.main(os.path.join(here, 'image.jpg'), False,
            os.path.join(here, 'brick.png'))
# legofy.main(image, brick=os.path.join(here, 'bricks', 'brick.png'))
Beispiel #19
0
 def test_full_process(self):
     here = os.path.abspath(os.path.dirname(__file__))
     image = os.path.join(here, 'image.jpg')
     legofy.main(image, output='lego_image.png')
     expected = os.path.join(here, 'lego_image.png')
     self.assertTrue(os.path.exists(expected))
Beispiel #20
0
import legofy
import os

brick_img = 'brick.png'
target_img = 'image.jpg'

here = os.path.abspath(os.path.dirname(__file__))
target_img_path = os.path.join(here, target_img)
brick_img_path = os.path.join(here, brick_img)

# print(here)
# print(legofy)
legofy.main(target_img_path, brick_img_path)
# legofy.main(image, brick=os.path.join(here, 'bricks', 'brick.png'))
Beispiel #21
0
 def test_small_brick(self):
     '''Test hitting the minimal brick size'''
     self.create_tmpfile('.png')
     legofy.main(FLOWER_PATH, output_path=self.out_path, size=1)
     self.assertTrue(Image.open(self.out_path).size == (30, 30))
Beispiel #22
0
 def test_dither_without_palette(self):
     '''Dithering without a palette should still work'''
     self.create_tmpfile('.png')
     legofy.main(FLOWER_PATH, output_path=self.out_path, dither=True)
     self.assertTrue(os.path.getsize(self.out_path) > 0)
Beispiel #23
0
def main(brick, bricknum, image, output):
    if not brick:
        here = os.path.abspath(os.path.dirname(__file__))
        brick = os.path.join(here, 'bricks', 'brick.png')
    legofy.main(image, brick, bricknum)
Beispiel #24
0
def main(brick, image, output, bricks):
    if not brick:
        here = os.path.abspath(os.path.dirname(__file__))
        brick = os.path.join(here, 'bricks', 'brick.png')
    if not bricks : bricks = 30
    legofy.main(image, brick=brick, bricks=bricks)
Beispiel #25
0
def main(brick, image):#, output):
    if brick:
        legofy.main(image, brick=brick)
    else:
        legofy.main(image)
Beispiel #26
0
def main(brick, bricknum, image, output):
    if not brick:
        here = os.path.abspath(os.path.dirname(__file__))
        brick = os.path.join(here, "bricks", "brick.png")
    legofy.main(image, brick, bricknum)
Beispiel #27
0
def main(brick, image):
    if not brick:
        here = os.path.abspath(os.path.dirname(__file__))
        brick = os.path.join(here, 'bricks', 'brick.png')
    legofy.main(image, brick=brick)
Beispiel #28
0
def main(image, output, size, palette, dither):
    '''Legofy an image!'''
    legofy.main(image, output_path=output, size=size,
                palette_mode=palette, dither=dither)
Beispiel #29
0
def main(image, output, size, palette, dither, optimize):
    '''Legofy an image!'''
    legofy.main(image, output_path=output, size=size,
                palette_mode=palette, dither=dither, minimize_bricks_number=optimize)
Beispiel #30
0
def main(image, output, bricks, brick, palette):
    '''Main entry point'''
    legofy.main(image, output_path=output, bricks=bricks, brick_path=brick, palette_mode=palette)
Beispiel #31
0
def main(brick, image, output, hd):
    if not brick:
        here = os.path.abspath(os.path.dirname(__file__))
        brick = os.path.join(here, 'bricks', 'brick.png')
    legofy.main(os.path.abspath(image), hd, brick=brick)
Beispiel #32
0
def main(image, output, bricks, brick):
    '''Main entry point'''
    if output:
        if bricks:
            if brick:
                legofy.main(image, output=output, bricks=bricks, brick_path=brick)
            else:
                legofy.main(image, output=output, bricks=bricks)
        elif brick:
            legofy.main(image, output=output, brick_path=brick)
        else:
            legofy.main(image, output=output)
    elif bricks:
        if brick:
            legofy.main(image, bricks=bricks, brick_path=brick)
        else:
            legofy.main(image, bricks=bricks)
    elif brick:
        legofy.main(image, brick_path=brick)
    else:
        legofy.main(image)
Beispiel #33
0
def main(image, output, bricks, brick):
    '''Main entry point'''
    legofy.main(image, output=output, bricks=bricks, brick_path=brick)