Giter Site home page Giter Site logo

swipswaps / batch-conversion-to-webp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kasipavankumar/batch-conversion-to-webp

0.0 1.0 0.0 13.16 MB

Handy Python script developed for web developers to converts all their images to the WebP format.

Python 100.00%

batch-conversion-to-webp's Introduction

WebP Converter

A Handy Python script that converts images to the WebP format.

It is always good to serve optimized & quality images on your website. The WebP format is always recommended for everything web.

The aim of this script is to convert all your images in batch & organize them to a new directory.

Why WebP?

WebP is the format developed with web in mind. It provides many performance benefits while serving the assets for your website.

Reference: web.dev

How the script works?

Demo

The script uses the WebP library provided by Google for the conversion process.

You are required to copy the provided script to the directory where all your images are being stored. Though not neccesary but suggested, that the directory should contain only the image files.

On running, the script will scan the current directory for images with extensions of '.jpg', '.jpeg' & '.png'. Next, using the following bash command, the script will convert the every selected image to '.webp' format.

Command: cwebp -q 80 image.jpg -o image.webp where, 80 = typical output quality.

Quality can be modified by editing the quality variable in the script.

Once converted, the images will be organized to a new directory named 'webp'.

The name of the directory can be modified by editing the dir_name variable in the script.

NOTE: Converted images will have the same name as they had before conversion.

Why this script?

The script is smart enough to:

  • Detect for the missing images after conversion & restore them accordingly.
  • Detect if the missing images are present in the original directory, it moves them accordingly and thus save you time by not converting existing images again.

More features are in progress.

How to run this script?

  1. Install the latest & stable version i.e., 3.8.1 of Python.
  2. Download the WebP library provided by Google. You can find the latest version i.e., 1.1.0 at bottom of the page.
  3. Extract the compressed folder & add path of the bin directory to your system variables. Path will look something like this: ..\libwebp-1.1.0-windows-x64\bin
  4. Enter cwebp -version in CLI, which will return the version number. This indicates a successful installation.
  5. You are ready to copy the script & use it.

I hope you find this script useful, cheers!


Code Plus Coffee

batch-conversion-to-webp's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.