Skip to main content

Generate a petting gif from a static image (known as "petpet", "Pet the X", or "PETTHE").

Project description

pet-pet-gif

Python adaptation of https://github.com/aDu/pet-pet-gif

Usage:

from petpetgif import petpet  
petpet.make(source, dest)
  • source: A filename (string), pathlib.Path object or a file object. (This parameter corresponds and is passed to the PIL.Image.open() method.)

  • dest: A filename (string), pathlib.Path object or a file object. (This parameter corresponds and is passed to the PIL.Image.save() method.)

Basic example:

from petpetgif import petpet
petpet.make('test.png', 'out.gif')

Discord.py example:

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from io import BytesIO
from typing import Union, Optional
from petpetgif import petpet as petpetgif

load_dotenv()
token = os.getenv('DISCORD_BOT_TOKEN')

client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('Bot is ready.')

@client.command()
async def pet(ctx, image: Optional[Union[discord.PartialEmoji, discord.member.Member]]):
    if type(image) == discord.PartialEmoji:
        image = await image.url_as(format='png').read() # retrieve the image bytes
    elif type(image) == discord.member.Member:
        image = await image.avatar_url_as(format='png').read() # retrieve the image bytes
    else:
        await ctx.reply('Please use a custom emoji or tag a member to petpet their avatar.')
        return

    source = BytesIO(image) # file-like container to hold the emoji in memory
    dest = BytesIO() # container to store the petpet gif in memory
    petpetgif.make(source, dest)
    dest.seek(0) # set the file pointer back to the beginning so it doesn't upload a blank file.
    await ctx.send(file=discord.File(dest, filename=f"{image[0]}-petpet.gif"))


client.run(token)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pet_pet_gif-1.0.2-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file pet_pet_gif-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pet_pet_gif-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.9.4

File hashes

Hashes for pet_pet_gif-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 935898313d0a2826fadc16dab652f947ebb10ef789f9cba97a72212eb96fb28e
MD5 c7a798d73e64428633f6b9573dd82d6a
BLAKE2b-256 8d97e29973f8880adab22c5b6f389cbf3f0ba64e97e4be0f4ba75d76843e31df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page