I'm new with shellscript and I'm having some problems trying to do what I need...
I want to 'optimize' all my *.png images and found this so I made the bash as it says with:
#!/bin/bash
pngnq -vf -s1 *.png
rename -nq8.png .png *-nq8*
optipng -o7 *.png
What this do is:
pngnq -vf -s1 *.png
takes a *png ofr example Image.png and craetes a copy named Image-nq8.png which is the one optimizedrename -nq8.png .png *-nq8*
makes Image-nq8.png become Image.png so you have the same as before but optimized (so you can have the same in the folders as you had before optimize) <= VERY IMPORTANT!optipng -o7 *.png
does another optimization to Images.png without making any copy.
But now I have a problem:
If I write in console every line in order, it works ok on the folder I am but now I need to do it automatically and recursive. I explain my case:
note: I say folder as a directory
I have a folder named ImagesFolder and inside I have other folders with more *.pngs and I want to run this bash in every subfolder of ImagesFolder but I don't know how to do it (as I said I'm new in unix and shellscripts and so on) and what I found on internet and tried didn't work or was a completly mess...
To understand it better what I have is something like:
ImagesFolder
|-Folder1
| |- Folder12
| | |-20 images here
| |- Folder13
| | |- 10 images more here
| |- _Folder <- I have some folder names that start with '_'
| |- 5 images here
|-more images and folders and subfoldrs
This is the structure and I want the script to run from ImagesFolder.
I tried with a for and a find in it, and with a find in console calling the script... tried too appling some examples I found here in stack but nothing... Probably is because as I don't really know how does this work I can't apply it just like that. Hope you can help me with this problem.
Thank you so much!
Edit: To run the script I have to go to ImageFolder, open a console and put chmod u+x name_of_my_script
could this be a problem to run it into the subfolders? If yes, can you tell me how to fix it?