When doing some of my research, I like to save pictures that I come across on my local machine for later reference or inspiration. WebP by Google is gradually being more used as an image format in the web, offering lossless & lossy compression at small file sizes than PNG or JPEG at similar quality.
Modern web browsers have no problem displaying these images, but the local machines on which I like to look at these images might not be always capable. Even newer operating systems will not always work well with WebP out of the box. Some of my image editors (including Photoshop) have no idea what to do with these files [No worries, Google offers a plug-in]. There are plenty of tools to display WebP files, but I might want to edit the images or look at them on a machine that might not have a viewer installed.
Since I don’t require the same levels of compression for the images on my Dropbox / local machines, I decided I would simply convert them to PNGs. Google’s webp package contains all the tools necessary to convert file to and from WebP, but using the Terminal is rather sub-optimal while browsing my photos. If I happen to download a WebP file, I want to right click it in my file manager (Currently Nemo for Cinnamon on Linux Mint) and automatically convert it to a PNG. Since switching to Linux, I’ve been in awe at the level of customization right at the users finger tips, so making a little context entry should not be too difficult! Nemo Actions to the rescue!
First we need to install the tools to convert WebP files:
sudo apt install webp
cwebp is used for compressing images to the webP format. We are interested in dwebp which is used to turn webP files into PNGs (or JPEGs). The command goes as follows:
dwebp original.webp -o converted.png
Pretty straight forward. But I don’t want to open Terminal every time and type this every time I download a WebP image. Enter Nemo Action. First we create a file for this particular Nemo Action:
You can give it any name you like as long as you place it in the right folder and add the extension .nemo_action.
Now paste the following into the file.
[Nemo Action] # This is the title of your context menu as it will appear Name=Convert WebP To PNG # Comment being displayed in the status bar at the bottom # We are using %f to display the filename without path Comment=Convert %f To PNG # The actual command - we are using %F for the full filename & path Exec=dwebp "%F" -o "%F".png # Grab yourself your favorite icon (Browse with gtk3-icon-browser) Icon-Name=media-floppy # Applies to selections of individual (single) files Selection=s # We only want this context menu to appear when selecting webp files Extensions=webp; # Don't show the context menu unless this dependency exists Dependencies=dwebp
One you save the file the context will appear when you right click on a webp file.