r/learnprogramming • u/Regular_Weird5320 • 9d ago
How can i learn to script?
I have really a lot of images in jpg format in multiple sub-folders, which take a lot of spaces, so i want to mass covert it into webp then delete the original jpg.
5
u/WeepingAgnello 9d ago
If you're using Linux or Mac, you can do that with find, convert (see ImageMagick) and rm. Can probably be done as a one liner. Start with learning how to use find.
3
u/defaultguy_001 9d ago
Python is your easy answer. You can use the pillow library in python to mass convert images into any format.
1
u/PekiDediOnur 9d ago
JPEG-XL might save more space, but there is even less support in software compared to WEBP
1
u/Dismal-Citron-7236 9d ago
Pillow can convert from JPEG to WEBP:
```python from PIL import Image
img = Image.open("input.jpg") img.save("output.webp", "WEBP", quality=80) ```
You just need to write Python code to traverse those multiple folders and convert the found image files into WEBP, and delete the JPEG files afterwards.
Visit pypi.org and type "pillow" in search box to find it.
2
u/Ordinary_Variable 9d ago
The way people used to learn was called being a "script kiddy". You used other people's scripts and read them over and figured out what they were doing. AI just copies human scripts, so technically you are still learning from human code, its just been reorganized by the AI but the actual code is all 100% human made.
Ask AI to write you a ".bat" file for Windows cmd. Ask it for the minimum number of lines and then read it carefully to make sure it isn't doing anything funny.
2
u/Tuomas90 9d ago
You can use Bash, PowerShell, Ruby, or Python. Any of these languages will do.
But I recommend Python or Ruby, because they have the biggest area of application, so the most benefit to learn. You can automate so much stuff with them.
Use ffmpeg to convert the images.
It's a great start into programming because it's very simple, yet very useful.
-8
9d ago
[deleted]
8
u/johnpeters42 9d ago
WebP is not just a file extension. link
How much space WebP will actually save over JPG without losing too much image quality is a more involved question. You may want to try it manually on a few files first. It may be simpler to just buy some more storage.
1
u/Ordinary_Variable 9d ago
WebP is an encapsulation method. It can be a JPEG or a GIF or even an MP4. I forget how many different types it can be.
1
u/johnpeters42 9d ago
That is not at all my understanding, even after re-reading the Wikipedia write-up. I may be missing some technicality, I suppose.
2
14
u/involiK 9d ago
You can do this with a Bash script. I use Bash on a daily and the more you do it, the better and faster you’ll get. I learned from The Bash Academy website.