HTML Script Code To Convert JPG PNG to WEBP Can Be Used On Blogger and WordPress

Hi friends, WPTokers, I will share an HTML code script to convert images with the extension PNG or JPG, JPEG to WEBP. This script can be used on Blogger and WordPress by going to the HTML edit menu in the page or post section and copying the script code that I have provided below. The usefulness of using these tools can add value to your blog or site because it is complete and suitable. This script is very light and easy for the users or visitors of your site. Visitors to your site who want to convert their image just drag and drop into the box provided and click on the converted image to download it.

HTML Script Code To Convert JPG PNG to WEBP


Related searches for this article:

  • simple and free image to webp converter script
  • free image to webp converter javascript code
  • image to webp converter HTML code for blogger
  • image to webp converter HTML code for WordPress
  • image to webp converter script for blogger
  • image to webp converter script for WordPress
  • image converter to webp PHP script
  • image converter to webp PHP 2022 script
  • HTML code for image to webp converter

HTML Script Code for Convert Image Files to WEBP

You just copy and paste the script code below, in a blogger or WordPress post or page, change your editor to HTML.

<div class="layout">
    <h1>WEBP Image Converter - wptoke.eu.org</h1>
    <div>
      <input accept="image/*" multiple="" type="file" />
    </div>
    <div id="previews"></div>
    <div class="dropTarget"></div>
  </div>

<style>
  input[type=file] { margin: 20px 0; } img { max-height: 100%; max-width: 100%; box-shadow: 0px 0px 25px 0px rgba(0,0,0,0.75); } .dropTarget { position: relative; border: 10px dashed silver; flex-basis: auto; flex-grow: 20; } .dropTarget::before { content: 'Drop files here'; color: silver; font-size: 5vh; height: 5vh; position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; text-align: center; pointer-events: none; user-select: none; } #previews > div { box-sizing: border-box; height: 240px; width: 240px; padding: 20px; display: inline-flex; justify-content: center; align-items: center; vertical-align: top; } #previews > div:after{ Content:'Click Image To Download'; display:block; font-weight:bold; font-size:10px; position: absolute;border:5px solid silver; padding: 2px 9px; background: #f7f7f7; } #previews > div > progress { width: 80%; } .layout { display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; align-content: stretch; height: calc(100vh - 40px); }
</style>


<script>
//<![CDATA[
  let refs = {}; refs.imagePreviews = document.querySelector('#previews'); refs.fileSelector = document.querySelector('input[type=file]'); function addImageBox(container) { let imageBox = document.createElement("div"); let progressBox = document.createElement("progress"); imageBox.appendChild(progressBox); container.appendChild(imageBox); return imageBox; } function processFile(file) { if (!file) { return; } console.log(file); let imageBox = addImageBox(refs.imagePreviews); new Promise(function (resolve, reject) { let rawImage = new Image(); rawImage.addEventListener("load", function () { resolve(rawImage); }); rawImage.src = URL.createObjectURL(file); }) .then(function (rawImage) { return new Promise(function (resolve, reject) { let canvas = document.createElement('canvas'); let ctx = canvas.getContext("2d"); canvas.width = rawImage.width; canvas.height = rawImage.height; ctx.drawImage(rawImage, 0, 0); canvas.toBlob(function (blob) { resolve(URL.createObjectURL(blob)); }, "image/webp"); }); }) .then(function (imageURL) { return new Promise(function (resolve, reject) { let scaledImg = new Image(); scaledImg.addEventListener("load", function () { resolve({imageURL, scaledImg}); }); scaledImg.setAttribute("src", imageURL); }); }) .then(function (data) { let imageLink = document.createElement("a"); imageLink.setAttribute("href", data.imageURL); imageLink.setAttribute('download', `${file.name}.webp`); imageLink.appendChild(data.scaledImg); imageBox.innerHTML = ""; imageBox.appendChild(imageLink); }); } function processFiles(files) { for (let file of files) { processFile(file); } } function fileSelectorChanged() { processFiles(refs.fileSelector.files); refs.fileSelector.value = ""; } refs.fileSelector.addEventListener("change", fileSelectorChanged); function dragenter(e) { e.stopPropagation(); e.preventDefault(); } function dragover(e) { e.stopPropagation(); e.preventDefault(); } function drop(callback, e) { e.stopPropagation(); e.preventDefault(); callback(e.dataTransfer.files); } function setDragDrop(area, callback) { area.addEventListener("dragenter", dragenter, false); area.addEventListener("dragover", dragover, false); area.addEventListener("drop", function (e) { drop(callback, e); }, false); } setDragDrop(document.documentElement, processFiles);//]]>
</script> 

Demo 

 For a demo, please click the box below.

 

Next Post Previous Post
No Comment
Add Comment
comment url