#!/bin/bash # Function to print help message function print_help() { app_name=${0##*/} echo "Syntax: $app_name " echo " -h: Display this help message" echo "Usage: " echo " $app_name input.png output.jpg" echo " $app_name '*.png' output.jpg" } # Check if help flag is provided if [[ "$1" == "-h" ]]; then print_help exit 0 fi # Check if input file is provided if [[ $# -lt 1 ]]; then echo "Error: Input file is required." print_help exit 1 fi # Assign input and output files input_file="$1" # If output file is not provided, use input file name with output extension if [[ $# -eq 1 ]]; then output_file="${input_file%.png}.jpg" else output_file="$2" fi # Convert the image convert "$input_file" -background white -alpha remove -alpha off "$output_file" if [[ $? -ne 0 ]]; then echo "Error: Image conversion failed." fi