Skip to content

Instantly share code, notes, and snippets.

@ykm11
Created August 30, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykm11/7b2d85e8eecefd0e4223c5ea1140ed62 to your computer and use it in GitHub Desktop.
Save ykm11/7b2d85e8eecefd0e4223c5ea1140ed62 to your computer and use it in GitHub Desktop.
for slack emoji
import cv2
import numpy as np
from PIL import Image
import re
import argparse
def create_rot_image(img_file, angle=-15, duration=40):
size = (128, 128)
center = (128//2, 128//2)
scale = 1.0
img = cv2.imread(img_file)
if img is None:
raise ValueError(f"Not found such a file {img_file}")
print("[+] Image Loaded")
img = cv2.resize(img, (128, 128))
images = []
for i in range(360//abs(angle)):
rot_angle = angle * i
rot_mat = cv2.getRotationMatrix2D(center, rot_angle, scale)
img_rot = cv2.warpAffine(img, rot_mat, size, flags=cv2.INTER_CUBIC)
img_rot = cv2.cvtColor(img_rot, cv2.COLOR_BGR2RGB)
black = [0, 0, 0]
white = [255, 255, 255]
img_rot[np.where((img_rot == black).all(axis=2))] = white
pil_img_rot = Image.fromarray(img_rot)
images.append(pil_img_rot)
savefile = re.sub(r".(png|jpg)$", ".gif", img_file)
images[0].save(savefile,
save_all=True, append_images=images[1:], optimize=False, duration=duration, loop=0)
print("[+] Rot Image Saved")
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("file")
arg_parser.add_argument("--angle", default=-15)
arg_parser.add_argument("--duration", default=40)
args = arg_parser.parse_args()
file_name = args.file
angle = int(args.angle)
duration = int(args.duration)
create_rot_image(file_name, angle, duration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment