html5 base64上传图片 生成缩略图

admin4年前html5788
use think\Image;
//获取图片的缩略图
function getThumb($url, $width = 257, $height = 0) {
    if(empty($url)) return '';
    if(strpos($url, 'http://') !== false || strpos($url, 'https://') !== false) {
        //华为云缩略图
        return !empty($height) ? $url.'?x-image-process=image/resize,w_'.$width.',h_'.$height.',limit_0' : $url.'?x-image-process=image/resize,w_'.$width.',limit_0';
    }else {
        //本地生成缩略图
        $thumb = '.'.str_replace(['/upload/', '.jpg', '.jpeg', '.png', '.gif', '.webp'], ['/thumbnail/', '_thumb.jpg', '_thumb.jpeg', '_thumb.png', '_thumb.gif', '_thumb.webp'], $url);
        require_once ROOT_PATH . 'thinkphp/library/think/Image.php';
        if(empty($height)) $height = $width;
        if(!file_exists($thumb)) {
            $image = Image::open('.'.$url);
            $image->thumb($width, $height, Image::THUMB_CENTER)->save($thumb);
        }
        return str_replace(['./'], ['/'], $thumb);
    }
    return $url;
}


相关文章

ico标签代码

<link rel="shortcut icon" href="/favicon.ico" />...

谷歌整站翻译链接

https://translate.google.com/translate?sl=auto&tl=zh-CN&u=www.metapes.com...

iphone打开视频禁用全屏iPhone视频禁全屏

HTML里video必须加上webkit-playsinline属性<video id="player" width="480" height="...

各大主机商主机控制面板网址

万网 https://cp.hichina.com/login西部数码 https://www.myhostadmin.net/...

html5加载动画效果

section {             width: ...

图片响应式

<picture>              &...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。