Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def do_gmagik(self, ctx, gif):
- try:
- try:
- gif = PIL.Image.open(gif)
- except:
- return '\N{WARNING SIGN} Invalid Gif.'
- if gif.size >= (3000, 3000):
- return '\N{WARNING SIGN} `GIF resolution exceeds maximum >= (3000, 3000).`'
- elif gif.n_frames > 150 and ctx.message.author.id != self.bot.owner.id:
- return "\N{WARNING SIGN} `GIF has too many frames (> 150 Frames).`"
- count = 0
- frames = []
- while gif:
- b = BytesIO()
- try:
- gif.save(b, 'GIF')
- except:
- continue
- b.seek(0)
- frames.append(b)
- count += 1
- try:
- gif.seek(count)
- except EOFError:
- break
- imgs2 = []
- for image in frames:
- try:
- im = wand.image.Image(file=image)
- except:
- continue
- i = im.clone()
- i.transform(resize='800x800>')
- i.liquid_rescale(width=int(i.width*0.5), height=int(i.height*0.5), delta_x=1, rigidity=0)
- i.liquid_rescale(width=int(i.width*1.5), height=int(i.height*1.5), delta_x=2, rigidity=0)
- i.resize(i.width, i.height)
- b = BytesIO()
- i.save(file=b)
- b.seek(0)
- imgs2.append(b)
- imgs2 = [PIL.Image.open(i) for i in imgs2]
- final = BytesIO()
- i = imgs2[0].save(final, 'GIF', loop=0, save_all=True, append_images=imgs2)
- final.seek(0)
- return final
- except Exception as e:
- return f'{str(e)} {e.__traceback__.tb_lineno}'
- async def do_gmagik2(self, url):
- path = self.files_path(self.bot.random(True))
- await self.download(url, path)
- args = ['convert', '(', path, '-resize', '256x256>', '-resize', '256x256<', ')']
- i = 5
- while i <= 70:
- args.extend(['(', '-clone', '0', '(', '+clone', '-liquid-rescale', '{0}%'.format(int(100-i)), ')', '(', '+clone', '-resize', '256', ')', '-delete', '-2', '-delete', '-2', ')'])
- i += 5
- args.extend(['-delay', '8', '-set', 'delay', '8', 'gif:-'])
- final = await self.bot.run_process(args, b=True)
- return path, final
- @commands.command(pass_context=True, aliases=['gmagick'])
- @commands.cooldown(1, 10, commands.BucketType.server)
- async def gmagik(self, ctx, url:str=None):
- try:
- x = await self.bot.say("ok, processing (this might take a while)")
- get_images = await self.get_images(ctx, urls=url, limit=1, gif=True, msg=False)
- if not get_images:
- get_images = await self.get_images(ctx, urls=url, limit=2)
- if get_images:
- url = get_images[0]
- if self.get_switch('gmagik2'):
- final = await self.generic_api('gmagik2', url)
- if isinstance(final, str):
- return await self.bot.say(final)
- else:
- path, final = await self.do_gmagik2(url)
- os.remove(path)
- await self.bot.upload(final, filename='gmagik.gif')
- else:
- ctx.command.reset_cooldown(ctx)
- return
- else:
- url = get_images[0]
- if self.get_switch(ctx.command.name):
- final = await self.g_api(url, ctx.message.author.id, 'gmagik')
- if not final:
- return await self.bot.say('\N{WARNING SIGN} **Command download function failed...**')
- else:
- b = await self.bytes_download(url)
- if sys.getsizeof(b) > 6500000 and ctx.message.author.id != self.bot.owner.id:
- return await self.bot.say("\N{NO ENTRY} `GIF Too Large (> 6.5 mb).`")
- final = await self.bot.loop.run_in_executor(None, self.do_gmagik, ctx, b)
- if isinstance(final, str):
- return await self.bot.say(final)
- await self.bot.upload(final, filename='gmagik.gif')
- except Exception as e:
- await self.bot.say(code.format(e))
- raise
- finally:
- await self.bot.delete_message(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement