I am assisting in making a wiki for an old game, and we ripped the avatar GIFs from the games shop and want to have a catalog of them. What I need to do is to crop all the borders which are identical from 3,170 GIFs and maybe make background transparent.

I haven’t used python in years, but I managed to cobble up something that almost works as a single image test, only issue is that it crops and outputs only the first frame:

from PIL import Image

if __name__ == "__main__":
    input_loc = "AvatarShopImages/80001.gif"
    output_loc = "Output/80001.gif"
    im = Image.open(input_loc)
    im = im.crop((4, 4, 94, 94))
    im.save(output_loc)

If it looks weird, it is because I copy/pasted some code and edited a lot out of it.

You are viewing a single thread.
View all comments
3 points

@Shady_Shiroe

Open GIMP
Go to “File” > “Open” and select your GIF.
Select the “Crop Tool” from the toolbox.
Adjust the crop area to your desired size.
Click the “Crop” button.
Go to “File” > “Export As” and choose GIF as the format. Save your cropped GIF.

FFmpeg
Use the following command to crop the GIF, replacing input.gif with your GIF’s filename and specifying the crop dimensions:

ffmpeg -i input.gif -vf “crop=w:h:x:y” output.gif

permalink
report
reply
3 points

Let me clarify, there are 3 THOUSAND GIFs that need to be cropped

permalink
report
parent
reply
7 points

for i in $( ls *.gif ); do fmpeg -i $i -vf “crop=w:h:x:y” cropped_$i; done

This runs on Linux/Mac or on WSL on windows Make sure there are no spaces in the filenames.

permalink
report
parent
reply
3 points
*

If they’re all the same size and need cropped to the same size you could drop them all in one folder and run the ffmpeg command with *.gif. That should do all of them.

You’d have to find a way to automate the output though.

permalink
report
parent
reply

Python

!python@programming.dev

Create post

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events
Past

November 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
  • Pythörhead: a Python library for interacting with Lemmy
  • Plemmy: a Python package for accessing the Lemmy API
  • pylemmy pylemmy enables simple access to Lemmy’s API with Python
  • mastodon.py, a Python wrapper for the Mastodon API
Feeds

Community stats

  • 719

    Monthly active users

  • 438

    Posts

  • 2.2K

    Comments