Here is a simple example:
Problem: The image url that you get from sharing a google drive image will be something like this
Simple Solution:
(**a) https://drive.google.com/file/d/{this part will contain the image ID that we need}/view?usp=sharing
But to use image we need url something like this
(**b) https://drive.google.com/uc?id={this part will contain the image ID that we need}
So the simple thing we can do is manually copying that part of the image ID from (**a) url and pasting in the (**b) url.
Automating using JavaScript:
let sharableLink = (**a); //paste the google drive image sharing link here
let baseUrl = "https://drive.google.com/uc?id=";
let imageId = sharableLink.substr(32, 33); //this will extract the image ID from the shared image link
let url = baseUrl.concat(imageId); //this will put the extracted image id to end of base Url
Here 32 and 33 are the starting and ending position of the image ID to be extracted from the shared image link.
AddOn:
You can create a simple HTML to get the converted image Url from the sharable link.
HTML:
sample.html
<!DOCTYPE html>
<html>
<head>
<body>
</div>
<!-- container for url and button to load it -->
<div class="thumbnail-container">
<input
type="text"
id="edt-thumbnail-url"
name="thumbnail-url"
placeholder="Thumbnail Url">
<div>
<button class="btn btn-load-thumbnail" id="btn-load-thumbnail">Upload Thumbnail</button>
</div>
</div>
<!-- script that runs the code for conversion -->
<script src="/sample.js"></script>
</body>
<head>
</html>
now create a javascript file and paste this
sample.js
const productThumbnailUrl = document.getElementById("edt-thumbnail-url");
const btnUploadThumbnail = document.getElementById("btn-load-thumbnail");
btnUploadThumbnail.addEventListener("click", (e) => {
e.preventDefault();
let str = productThumbnailUrl.value;
let baseUrl = "https://drive.google.com/uc?id=";
let imageId = str.substr(32, 33);
let url = baseUrl.concat(imageId);
productThumbnailUrl.value = url; //this will put the converted url in the edit text box
console.log(url);
});