Example #1
0
def print_photo(photo: telegram.PhotoSize):
    new_path = f'./tmp/{photo.file_id.replace(" ", "_")}.jpg'

    open(new_path, 'wb').close()
    try:
        with open(new_path, 'wb') as f:
            photo.get_file().download(out=f)
    except Exception as e:
        print(e)
    try:
        orientation = 3 if settings[ORIENTATION] is Orientation.portrait else 4
        command = f'lpr -# {settings[COPIES]} ' \
                  f'-o orientaion-requested={orientation} ' \
                  f'-P CLP-320-Series ' \
                  f'{new_path}'

        res = subprocess.run(args=command.split(),
                             check=True,
                             stdout=subprocess.PIPE,
                             text=True)
        print(res)
    except Exception as e:
        print(e)

    printer_await()

    os.remove(new_path)
Example #2
0
    def watermark_photo(self, photo: PhotoSize) -> BytesIO:
        direction = self.channel_settings.image_caption_direction
        image_caption = self.channel_settings.image_caption
        file: File = photo.get_file()

        extension = os.path.splitext(file.file_path)[1].strip('.')

        image_in = BytesIO()
        image_out = BytesIO()
        file.download(out=image_in)
        alpha = int(self.channel_settings.image_caption_alpha / 100 * 255)

        watermark_text(
            in_image=image_in,
            out_buffer=image_out,
            text=image_caption,
            file_extension=extension,
            pos=direction,
            font=self.channel_settings.image_caption_font,
            alpha=alpha,
        )

        return image_out