当前位置: 首页 > news >正文

全媒体门户网站建设怎么进行网站关键词优化

全媒体门户网站建设,怎么进行网站关键词优化,佛山 网站建设培训班,服务器怎么设置ip做网站<?php namespace app\lib; /** * 图片压缩类&#xff1a;通过缩放来压缩。 * 如果要保持源图比例&#xff0c;把参数$percent保持为1即可。 * 即使原比例压缩&#xff0c;也可大幅度缩小。数码相机4M图片。也可以缩为700KB左右。如果缩小比例&#xff0c;则体积会更小。…

<?php
namespace app\lib;

/**
 * 图片压缩类:通过缩放来压缩。
 * 如果要保持源图比例,把参数$percent保持为1即可。
 * 即使原比例压缩,也可大幅度缩小。数码相机4M图片。也可以缩为700KB左右。如果缩小比例,则体积会更小。
 * 结果:可保存、可直接显示。
 */
class ImageCompress
{

    private $src;

    private $image;

    private $imageinfo;

    private $percent = 0.5;

    /**
     * 图片压缩
     * 
     * @param $src 源图            
     * @param float $percent 压缩比例
     * 
     */
    public function __construct($src, $percent = 1)
    {
        $this->src = $src;
        $this->percent = $percent;
    }

    /**
     * 高清压缩图片
     * 
     * @param string $saveName
     * 提供图片名(可不带扩展名,用源图扩展名)用于保存。或不提供文件名直接显示
     */
    public function compressImg($saveName = '')
    {
        $this->_openImage();
        if (! empty($saveName))
            $this->_saveImage($saveName); // 保存
        else
            $this->_showImage();
    }

    /**
     * 内部:打开图片
     */
    private function _openImage()
    {
        list ($width, $height, $type, $attr) = getimagesize($this->src);
        $this->imageinfo = array(
            'width' => $width,
            'height' => $height,
            'type' => image_type_to_extension($type, false),
            'attr' => $attr
        );
        $fun = "imagecreatefrom" . $this->imageinfo['type'];
        $this->image = $fun($this->src);
        $this->_thumpImage();
    }

    /**
     * 内部:操作图片
     */
    private function _thumpImage()
    {
        $new_width = $this->imageinfo['width'] * $this->percent;
        $new_height = $this->imageinfo['height'] * $this->percent;
        $image_thump = imagecreatetruecolor($new_width, $new_height);
        // 将原图复制到图片载体上面,并且按照一定比例压缩,极大的保持了清晰度
        imagecopyresampled($image_thump, $this->image, 0, 0, 0, 0, $new_width, $new_height, $this->imageinfo['width'], $this->imageinfo['height']);
        imagedestroy($this->image);
        $this->image = $image_thump;
    }

    /**
     * 输出图片:保存图片则用saveImage()
     */
    private function _showImage()
    {
        header('Content-Type: image/' . $this->imageinfo['type']);
        $funcs = "image" . $this->imageinfo['type'];
        $funcs($this->image);
    }

    /**
     * 保存图片到硬盘:
     * 
     * @param string $dstImgName
     *            1、可指定字符串不带后缀的名称,使用源图扩展名 。2、直接指定目标图片名带扩展名。
     */
    private function _saveImage($dstImgName)
    {
        if (empty($dstImgName))
            return false;
        $allowImgs = [
            '.jpg',
            '.jpeg',
            '.png',
            '.bmp',
            '.wbmp',
            '.gif'
        ]; 
        // 如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
        $dstExt = strrchr($dstImgName, ".");
        $sourseExt = strrchr($this->src, ".");
        if (! empty($dstExt))
            $dstExt = strtolower($dstExt);
        if (! empty($sourseExt))
            $sourseExt = strtolower($sourseExt);
        // 有指定目标名扩展名
        if (! empty($dstExt) && in_array($dstExt, $allowImgs)) {
            $dstName = $dstImgName;
        } elseif (! empty($sourseExt) && in_array($sourseExt, $allowImgs)) {
            $dstName = $dstImgName . $sourseExt;
        } else {
            $dstName = $dstImgName . $this->imageinfo['type'];
        }
        $funcs = "image" . $this->imageinfo['type'];
        $funcs($this->image, $dstName);
    }

    /**
     * 销毁图片
     */
    public function __destruct()
    {
        imagedestroy($this->image);
    }
}

//应用举例
// public function condense_img($source)
// {
//     $path = 'uploads/jd_big_img/'.date('Ymd');
//     if(!file_exists($path)){
//         mkdir($path,0777,true);
//     }
//     $image_name = md5(time().$source);
//     $dst_img = $path.'/'.$image_name.'.jpg';
//     $percent = 1;  #原图压缩,不缩放,但体积大大降低
//     $image = (new Compress($source,$percent))->compressImg($dst_img);
//     return $dst_img;
// }
 //绝对路径
            $filePath = str_replace('\\', '/', get_local_upload_url().$savename);
            $allowImgs = ['jpg','jpeg','png','bmp','wbmp','gif']; 
            if($file->getSize() > 1024 && in_array($ext, $allowImgs)){
                (new ImageCompress($filePath,0.8))->compressImg($filePath);
            }

http://www.tj-hxxt.cn/news/62298.html

相关文章:

  • discuz 科技网站模板下载网络市场调研的方法
  • 搭建网站的企业网络营销的概念和特点
  • 做一个公司网站市场推广和销售的区别
  • 那个网站做的好关键词排名优化公司哪家好
  • 找家里做的工作上哪个网站简易的旅游网页制作
  • 新闻类网站开发难点关键词调词平台费用
  • 做网站的基础架构下载百度app最新版并安装
  • 备案 通过后 网站打不开西安seo网站建设
  • 国家税务总局官网查询搜索关键词优化
  • 建材行业网站建设方案安新seo优化排名网站
  • 物流查询网站开发商品推广软文800字
  • 中文域名的价值网络营销优化
  • 知名seo网站优化营销推广方式都有哪些
  • 建设网站需要服务器思亿欧seo靠谱吗
  • 成都网站建设116web天津seo技术教程
  • 想自己做淘宝有什么网站网络软文
  • 网站优化怎么做 有什么技巧关键词挖掘查询工具
  • 网站内容页设计专业软文发布平台
  • 学习软件的网站百度关键词seo年度费用
  • 网站建设计划书图片外链生成器
  • 哪个网站做代购seo中文意思
  • 广州微网站建设网络服务器的功能
  • 中国互联网协会会员重庆seo教程
  • 静安区网站开发营销网站建设教学
  • 网站开发路径百度seo关键词排名优化软件
  • 海口仿站定制模板建站seo海外
  • 深圳创业项目网络seo是什么
  • 手机网站管理工具推广策划方案模板
  • 开源网站模板网络营销pdf
  • 网站的相关搜索css代码怎么做百度手机浏览器