Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to rename images according to their size?

I downloaded a bunch on images using wget, and unfortunately, there was a huge drawback...

The downloaded images had the same name! So, the script automatically appended .1, .2 , ...etc. at the end:

Accept-Male-User-icon.png
Accept-Male-User-icon.png.1
Accept-Male-User-icon.png.2
...

So, am looking for a script that would take these files and rename them according to their size, given that their size could be one of the following:

(256x256, 128x128, 64x64, 48x48, 32x32, 16x16)

So I end up with something like this:

Accept-Male-User-icon256.png
Accept-Male-User-icon128.png
Accept-Male-User-icon64.png
...

Thanks!!

like image 268
Mazyod Avatar asked Dec 13 '22 16:12

Mazyod


1 Answers

If you have ImageMagick installed, you can try:

for a in *.png*; do mv -i $a ${a%\.png*}`identify -format '%w' $a`.png; done

Test it and if it works, remove the -i switch after mv.

like image 165
eumiro Avatar answered Dec 20 '22 19:12

eumiro