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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pierrebalian
Posts: 1
Joined: 2019-03-29T12:45:53-07:00
Authentication code: 1152

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

Post by pierrebalian » 2019-03-29T12:56:00-07:00

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.

Post Reply