Change .webp to .jpg with Linux shell script

Change .webp to .jpg

You can convert .webp files to .jpg using a Linux shell script by utilizing tools such as imagemagick or libwebp. Below is an example of a script that uses imagemagick, which provides the convert command:

  1. Install ImageMagick (if not already installed):
    sudo apt-get install imagemagick
  2. Create the shell script:
    #!/bin/bash
    
    # Directory containing .webp files
    DIRECTORY="path_to_your_directory"
    
    # Loop through all .webp files in the directory
    for FILE in "$DIRECTORY"/*.webp; do
      # Get the base name of the file (without extension)
      BASENAME=$(basename "$FILE" .webp)
      # Convert to .jpg
      convert "$FILE" "$DIRECTORY/$BASENAME.jpg"
    done
    
    echo "Conversion completed!"
  3. Make the script executable:
    chmod +x convert_webp_to_jpg.sh
  4. Run the script:
    ./convert_webp_to_jpg.sh

    Replace path_to_your_directory with the actual path to the directory containing your .webp files. This script will loop through each .webp file in the specified directory, convert it to a .jpg file with the same base name, and save it in the same directory.

If you prefer to use libwebp, here’s an alternative script:

  1. Install libwebp tools (if not already installed):
    sudo apt-get install webp
  2. Create the shell script:
    #!/bin/bash
    
    # Directory containing .webp files
    DIRECTORY="path_to_your_directory"
    
    # Loop through all .webp files in the directory
    for FILE in "$DIRECTORY"/*.webp; do
      # Get the base name of the file (without extension)
      BASENAME=$(basename "$FILE" .webp)
      # Convert to .jpg
      dwebp "$FILE" -o "$DIRECTORY/$BASENAME.jpg"
    done
    
    echo "Conversion completed!"
  3. Make the script executable:
    chmod +x convert_webp_to_jpg.sh
  4. Run the script:
    ./convert_webp_to_jpg.sh

    Again, replace path_to_your_directory with the actual path to your directory containing .webp files. This script will also convert each .webp file in the specified directory to a .jpg file with the same base name.

5/5 - (2 votes)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top