Page 1 of 1

Convert all tiffs and ignore alpha channel UNLESS filename contains text string?

Posted: 2019-03-29T12:56:00-07:00
by pierrebalian
Hello,

I was wondering if someone could help me craft a bash command to convert all .tiff on our server. I would like to convert all the .tiff to png. I would like to ignore all alpha channels UNLESS the filename contains the text "cut" (case agnostic), and if it does contain that text to save the image WITH the alpha channel intact.

As far as I am is

Code: Select all

for f in *.tif; do  echo "Converting $f"; convert "$f" -alpha off  "$(basename "$f" .tif).png"; done 
For the regular tiff files

and

Code: Select all

for f in *.tif; do  echo "Converting $f"; convert "$f"  "$(basename "$f" .tif).png"; done
for the images with cut in the filename.

What I am unsure on is how to regex to look for the text in the filename, and how to handle the logic of if matches run this, else run that.