Reputation: 7736
I have many PNGs uploaded by users.
However, they have white spaces around, which should be removed.
For instance:
An image like this:
Should be cropped to an image like this:
What should I do if I want to do this to all files matching *_spec.PNG
files in a directory and all its subdirectories?
Example files:
Folder
|
Subfolder1 - file1_spec.png
- file2_spec.png
- file3.png
|
Subfolder2 - filea.png
- fileb1_spec.png
I need to do this to these files:
Update:
Upvotes: 2
Views: 1029
Reputation: 207465
I would make a COPY of your files in a spare directory before you do anything. Then go to the top directory and run:
find . -iname "*_spec.png" -exec mogrify -trim {} \;
Note that there are more efficient ways of doing this, but they are less readable and only really worth it if you have tens of thousands of files, or more. For anyone who's interested, that means using GNU Parallel and/or trimming more than one file per invocation of ImageMagick to better amortize the process creation time over multiple files.
Upvotes: 4