VC

Size: a a a
VC

PD
function prepareUrl(url, widthImage, webpSupported = false) {
const urlWithoutParams = url.split("?")[0];
let preparedUrl = `${urlWithoutParams}?w=${widthImage}`;
const formatsForConverts = ["jpg", "gif", "png", "bmp", "ico"];
const convertParams = webpSupported ? "&fm=jpg" : "&fm=webp&lossless=true";
const imageExtension = urlWithoutParams.match(/\.([^\./\?]+)($|\?)/)[1];
if (formatsForConverts.some(format => format === imageExtension)) {
preparedUrl = `${preparedUrl}${convertParams}`;
}
return preparedUrl;
}АЗ
PD
`
function prepareUrl(url, widthImage, webpSupported = false) {
url = new URL(url);
url.search = new URLSearchParams({ w: widthImage });
if (/\.(jpg|gif|png|bmp|ico)(\?|$)/.test(url.pathname)) {
url.searchParams.set('fm', webpSupported ? 'jpg' : 'webp');
if (!webpSupported) url.searchParams.set('lossless', true);
}
return url.toString();
} А
АЗ
А
АЗ
А
АЗ
А
А
АЗ
АЗ
А
D
А
АЗ
D
АЗ