function checkWebp() {
try{
return (document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') == 0);
}catch(err) {
return false;
}
}
$(document).ready(function() {
var webp_good = checkWebp();
if(webp_good == false) {
$('img').each(function() {
var src = $(this).attr('src');
if(typeof src != 'undefined') {
src = src.replace('/format,webp', '/format,jpg');
$(this).attr('src', src);
}
var original = $(this).attr('original');
if(typeof original != 'undefined') {
original = original.replace('/format,webp', '/format,jpg');
$(this).attr('original', original);
}
})
}
})
function get_thumb($url, $type = '', $width = 0, $height = 0, $format = 'webp')
{
if(strpos($url, 'http://static.jutubao.com') !== false || strpos($url, 'http://img.jutubao.com') !== false) {
$accept = request()->header('accept');
if(strpos($accept, 'image/webp') === false && $format == 'webp') {
$format = 'jpg';
}
if(empty($width) && empty($height) && empty($type)) {
$url .= '?x-oss-process=image/format,'.$format;
} else {
$url .= '?x-oss-process=image/resize,m_'.$type.',h_'.$height.',w_'.$width.'/format,'.$format;
}
}
return $url;
}