5

I very recently installed Ubuntu 20.04 on my laptop and have been having this issue where I can't open most of the images I have saved. I get an error that says

Unrecognized Image File Format

(but they are literally just jpgs and PNGs).

I've tested the images by moving them to my thumb drive and then my Windows PC and they open up fine. I can also select Open with Firefox and that works but it's inconvenient. I've attempted to rename them and have the same issue. I've tried updating, upgrading, rebooting, and opening the images from the terminal and still I can't open some dumb wallpaper I saved from reddit.

How do I go about fixing this?


Update:

so I was able to figure this out, as it turns out these were webp images, which is odd because they all saved under .jpg or even .png without me intervening. So I've installed something that can view them properly, but there's still an issue. If I were to link an image in an email or on a website or something I won't be able to actually see what it is I'm linking unless I were to open up in a separate window first. So I'm unsure what to do about that.

source: OP's comment

7
  • What software do you open them with?
    – JoKeR
    Commented Apr 28, 2020 at 19:44
  • @JoKeR Well, I've used the default image viewer it came installed with, ViewNoir, and ShotWell. Interestingly, I just realized ShotWell gives me an error that says photo source file missing instead.
    – John Doe
    Commented Apr 28, 2020 at 19:51
  • I think you're just missing some libraries, install gimp and check.
    – JoKeR
    Commented Apr 28, 2020 at 20:35
  • @JoKeR I did that and rebooted. The images can be opened in gimp, but still not the gallery viewer.
    – John Doe
    Commented Apr 28, 2020 at 21:39
  • 1
    @Murphy so I was able to figure this out, as it turns out these were webp images, which is odd because they all saved under .jpg or even .png without me intervening. So I've installed something that can view them properly, but there's still an issue. If I were to link an image in an email or on a website or something I won't be able to actually see what it is I'm linking unless I were to open up in a separate window first. So I'm unsure what to do about that.
    – John Doe
    Commented May 2, 2020 at 5:55

5 Answers 5

8

The 90% of the images that you were unable to open are .webp image files which are becoming more and more common on the web. webP uses the modern VP8 compression format to deliver efficient compression of images for the web. More than 30% extra gain over optimized JPEG for the same quality is not unusual. You can see the difference in quality when you decompress a .webp file.

In all currently supported versions of Ubuntu open the terminal and type:

sudo apt install webp

In Ubuntu 22.04 and later installing the webp-pixbuf-loader package will show the thumbnail images for webp files in Files file manager.

sudo apt install webp-pixbuf-loader

Let's assume you have an image file named FILE that doesn't show a thumbnail image in Files file manager and returns an Unrecognized Image File Format error when you try to open it. To convert a .webp file named FILE to .png run the following command.

dwebp FILE -o output_image.png 

To convert webp to .png run the following command.

dwebp input_image.webp -o output_image.png # or output_image.jpg for jpg

To convert webp to .png with ImageMagick run the following command.

convert input.webp output.png
find . -type f -name "*.webp"  -exec rename 's/.webp/.png/' {} +'

To convert multiple webp files to .png run the following command.

for x in ./*.webp; do
  convert "${x%}" "${x%}".png
done
find . -type f -name "*.webp.png" -exec rename 's/.webp//' {} +

The webp package also contains the cwebp command. cwebp compresses an image using the WebP format. Input format can be either PNG, JPG, TIFF, WebP or raw Y'CbCr samples.

1
  • 2
    Worth being doubly clear that sudo apt install webp isn't an a solution for viewing webp natively but rather the provider of dwebp to facilitate conversion to, say, png.
    – John
    Commented Jan 19, 2022 at 20:32
1

I share my primitive script that I use to convert webp files to more traditional formats. This way they can be used anywhere in the default Ubuntu desktop, including working thumbnails in Nautilus.

Please note: I'm a hobbyist in this department, not a reliable expert. If you use / tinker on this script, that's your choice and responsibility.

The script depends on the webp package being installed. It iterates over every *.webp file found in a given directory and its sub-directories recursively.

It converts to png, because that's my preference, but that can be changed in the line starting with dwebp. Alternatively a variable could be introduced for the fileneme extension, to make it more ergonomic.

It also has a fallback action, because sometimes dwebp fails to convert: in my experience, sometimes files saved with .webp extension (by Firefox) are still just regular .jpg's or .png's inside. Then dwebp returns with an error. I figured most of the time, such files are .jpg's so in the fallback action I rename them as such. I think it would be very well possible to make the script find out the true format in such cases; but since it happens so infrequently, I just rather search for the the filename segment "webp-convert-fallback" in Nautilus, see if any of them fails to show a thumbnail, and try to rename them to other extensions manually (usually they are either .png's or .gif's then).

Also there was a challenge with filenames containing spaces, but I kept refactoring until it worked (on GNU bash version 5.0.17).

#!/bin/bash

CURRENTDIR=$(pwd);

# See https://stackoverflow.com/questions/4638874/how-to-loop-through-a-directory-recursively-to-delete-files-with-certain-extensi/15088473#15088473
# See https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find#answer-9612560
find $CURRENTDIR -name '*.webp' -print0 | while read -d $'\0' file
do
    # echo $file && continue

    # See https://stackoverflow.com/questions/29505788/bash-dirname-basename-problems-with-spaces#answer-29505840
    dirname=`dirname "$file"`
    # echo $dirname && continue

    # See https://linuxhandbook.com/basename/
    basename=`basename "$file" .webp`
    # echo $basename && continue
    
    # See https://gist.github.com/earthgecko/3089509
    rando=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)

    dwebp "${file}" -o ${dirname}/"${basename}".webp-convert-${rando}.png

    # See https://linuxhint.com/check_command_succeeded_bash/
    if [ $? -eq 0 ]; then
        echo "========> DWEBP seemed successful:"
        echo "========> Putting ${basename}.webp into the Trash."

        # See https://askubuntu.com/questions/213533/command-to-move-a-file-to-trash-via-terminal
        # gvfs-trash "$file" # Older standard.
        gio trash "$file"    # Newer standard.
    else
        echo "########> Failed converting $file"
        mv "$file" "${dirname}/${basename}.webp-convert-fallback.jpg";
    fi
done;

Additionally I quickly mention, that in Firefox it is (at least it was) possible to disable working with .webp images. This would work such way that Firefox would send such request headers to the web-servers that suggest that it cannot deal with webp files; normally it should trigger web-servers to send the image in a traditional format. (Search for "webp" in Firefox's about:config page.)

But I stopped opting out from using webp's this way, because I have encountered a webshop that did not provide fallback images; seeing no images in a webshop made it pretty much unusable. Thus I had to give in, and let Firefox use webp's; that's how I ended up with the converting script.

1

I wrote a script so that whenever I double click on a .webp file, it autoconverts it to .png and replaces the original image. This makes it instantaneous to download an image and then view it in nemo.

#!/bin/bash
# Convert webp to png
# Must install: sudo apt install webp

file="$1"
out=`basename "$file" | sed 's/\.webp//'`.png
echo "Output $out"
cd `dirname "$file"`

dwebp "$file" -o "$out" && rm "$file" 

Save the script as webp2png.sh and make it executable. Then simply associate .webp files with the script, by right clicking->"open with" and navigating to the script.

Don't forget to install webp with: sudo apt install webp if you don't have it yet.

0

qView is a lightweight image viewer that supports .webp.

Enter the following commands to install it from its official PPA.

sudo add-apt-repository ppa:jurplel/qview
sudo apt update
sudo apt-get --install-suggests install qview

If you don't want to add another PPA, you can simply get the .deb/appimage/flatpak instead.

0

ImageMagick (terminal command: display) will open just about anything nowadays. It's not real picky as to what the file extension shows as, either, unlike most distros photo viewers. You might not find it in your menus, but you should be able to "open with" when selecting any image format (tif, png, jpeg, jpg, webp, etc.) in the context menu (right click a picture file) of your file manager. AND it has a bunch of options in its menus, such as finding all image info (in the misc. section) or saving as just about any format (that's in file> save> format button (and then type in a name (even the current name) including matching file extension, such as jpg. It's included in most distros! Yes, it's a little hard to use with the menus it has. But read the documentation and you'll be amazed: imagemagick.org

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .