js333 > 计算机互联网 > 采集远程网站图片保存到本地,采集远程服务器

原标题:采集远程网站图片保存到本地,采集远程服务器

浏览次数:155 时间:2019-09-28

class GetImage {

$message   //文章内容

php实用实例 采集远程网站图片保存到本地
先从文章中把所有<img ...> 用正则 抠出来. $message   //文章内容

$message   //文章内容

 

    //正则(这个还不是)

    //正则(这个还不是)

    //正则(这个还不是)

var $source;

    $reg = "/<img[^>]*src="(";

    $reg = "/<img[^>]*src="(";

    $reg = "/<img[^>]*src="(";

var $save_to;

    //把抠出来的 img 地址存放到 $img_array 变量中

    //把抠出来的 img 地址存放到 $img_array 变量中

    //把抠出来的 img 地址存放到 $img_array 变量中

var $quality;

    preg_match_all($reg, $message, $img_array, PREG_PATTERN_ORDER);

    preg_match_all($reg, $message, $img_array, PREG_PATTERN_ORDER);

    preg_match_all($reg, $message, $img_array, PREG_PATTERN_ORDER);

 

    //过滤重复的图片

    //过滤重复的图片

    //过滤重复的图片

function download($method = 'curl') {

    $img_array = array_unique($img_array[1]);

    $img_array = array_unique($img_array[1]);

    $img_array = array_unique($img_array[1]);

    $info = @GetImageSize($this->source);

复制代码

复制代码第二步. 把$img_array 数组循环一下. 做图片保存和文章位置替换 foreach ($img_array as $img){

复制代码第二步. 把$img_array 数组循环一下. 做图片保存和文章位置替换 foreach ($img_array as $img){

    $mime = $info['mime'];

第二步. 把$img_array 数组循环一下. 做图片保存和文章位置替换

        //判断是否是自己网站上的 图片

        //判断是否是自己网站上的 图片

   

foreach ($img_array as $img){

        if('xxx.com' != get_domain($img)){// 如果这个图片不是自己服务器上的

        if('xxx.com' != get_domain($img)){// 如果这个图片不是自己服务器上的

// What sort of image?

        //判断是否是自己网站上的 图片

            //读取图片文件

            //读取图片文件

    $type = substr(strrchr($mime, '/'), 1);

        if('xxx.com' != get_domain($img)){// 如果这个图片不是自己服务器上的

            $Gimg = new GetImage();

            $Gimg = new GetImage();

    switch ($type){

            //读取图片文件

            $Gimg->source = $img;

            $Gimg->source = $img;

        case 'jpeg':

            $Gimg = new GetImage();

            $Gimg->save_to = './data/temp/';

            $Gimg->save_to = './data/temp/';

            $image_create_func = 'ImageCreateFromJPEG';

            $Gimg->source = $img;

            $FILE =  $Gimg->download(); //图片移动到本地

            $FILE =  $Gimg->download(); //图片移动到本地

            $image_save_func = 'ImageJPEG';

            $Gimg->save_to = './data/temp/';

            //保存到相册 得到图片保存的位置

            //保存到相册 得到图片保存的位置

            $new_image_ext = 'jpg';

            $FILE =  $Gimg->download(); //图片移动到本地

            $img_path = pic_save($FILE,0,'');

            $img_path = pic_save($FILE,0,'');

       

            //保存到相册 得到图片保存的位置

            //文本路径替换

            //文本路径替换

            // Best Quality: 100

            $img_path = pic_save($FILE,0,'');

            $message = str_replace($img, $img_path, $message);

            $message = str_replace($img, $img_path, $message);

            $quality = isSet($this->quality) ? $this->quality : 100;

            //文本路径替换

           

           

            break;

            $message = str_replace($img, $img_path, $message);

        }

        }

       

            

    }

    }

        case 'png':

        }

 

 

            $image_create_func = 'ImageCreateFromPNG';

    } 

    ....这时候 $message 里面已经图片已经替换为自己服务器本地的地址,并且图片也保存到自己的服务器上.

    ....这时候 $message 里面已经图片已经替换为自己服务器本地的地址,并且图片也保存到自己的服务器上.

            $image_save_func = 'ImagePNG';

    ....这时候 $message 里面已经图片已经替换为自己服务器本地的地址,并且图片也保存到自己的服务器上.

复制代码//下面一个函数 和 类是从网络上找的.

复制代码//下面一个函数 和 类是从网络上找的.

            $new_image_ext = 'png';

复制代码

 

 

       

//下面一个函数 和 类是从网络上找的.

//从url中获得域名

//从url中获得域名

            // Compression Level: from 0  (no compression) to 9

//从url中获得域名

function get_domain($url){

function get_domain($url){

            $quality = isSet($this->quality) ? $this->quality : 0;

function get_domain($url){

    $pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";

    $pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";

            break;

    $pattern = "/[w-]+.(com|net|org|gov|cc|biz|info|cn)(.(cn|hk))*/";

    preg_match($pattern, $url, $matches);

    preg_match($pattern, $url, $matches);

       

    preg_match($pattern, $url, $matches);

    if(count($matches) > 0) {

    if(count($matches) > 0) {

        case 'bmp':

    if(count($matches) > 0) {

        return $matches[0];

        return $matches[0];

            $image_create_func = 'ImageCreateFromBMP';

        return $matches[0];

    }else{

    }else{

            $image_save_func = 'ImageBMP';

    }else{

        $rs = parse_url($url);

        $rs = parse_url($url);

            $new_image_ext = 'bmp';

        $rs = parse_url($url);

        $main_url = $rs["host"];

        $main_url = $rs["host"];

            break;

        $main_url = $rs["host"];

        if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {

        if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {

       

        if(!strcmp(long2ip(sprintf("%u",ip2long($main_url))),$main_url)) {

            return $main_url;

            return $main_url;

        case 'gif':

            return $main_url;

        }else{

        }else{

            $image_create_func = 'ImageCreateFromGIF';

        }else{

            $arr = explode(".",$main_url);

            $arr = explode(".",$main_url);

            $image_save_func = 'ImageGIF';

            $arr = explode(".",$main_url);

            $count=count($arr);

            $count=count($arr);

            $new_image_ext = 'gif';

            $count=count($arr);

            $endArr = array("com","net","org","3322");//com.cn  net.cn 等情况

            $endArr = array("com","net","org","3322");//com.cn  net.cn 等情况

 

            $endArr = array("com","net","org","3322");//com.cn  net.cn 等情况

            if (in_array($arr[$count-2],$endArr)){

            if (in_array($arr[$count-2],$endArr)){

            break;

            if (in_array($arr[$count-2],$endArr)){

                $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];

                $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];

       

                $domain = $arr[$count-3].".".$arr[$count-2].".".$arr[$count-1];

            }else{

            }else{

        case 'vnd.wap.wbmp':

            }else{

                $domain =  $arr[$count-2].".".$arr[$count-1];

                $domain =  $arr[$count-2].".".$arr[$count-1];

            $image_create_func = 'ImageCreateFromWBMP';

                $domain =  $arr[$count-2].".".$arr[$count-1];

            }

            }

            $image_save_func = 'ImageWBMP';

            }

            return $domain;

            return $domain;

            $new_image_ext = 'bmp';

            return $domain;

        }// end if(!strcmp...)

        }// end if(!strcmp...)

            break;

        }// end if(!strcmp...)

    }// end if(count...)

    }// end if(count...)

       

    }// end if(count...)

}// end function

}// end function

        case 'xbm':

}// end function

 

 

            $image_create_func = 'ImageCreateFromXBM';

// 从远程吧图片载到服务器本地 的 类

// 从远程吧图片载到服务器本地 的 类

// 从远程吧图片载到服务器本地 的 类

            $image_save_func = 'ImageXBM';

class GetImage {

class GetImage {

class GetImage {

            $new_image_ext = 'xbm';

var $source;

 

 

            break;

var $save_to;

var $source;

var $source;

       

var $quality;

var $save_to;

var $save_to;

        default:

function download($method = 'curl') {

var $quality;

var $quality;

            $image_create_func = 'ImageCreateFromJPEG';

    $info = @GetImageSize($this->source);

 

 

            $image_save_func = 'ImageJPEG';

    $mime = $info['mime'];

function download($method = 'curl') {

function download($method = 'curl') {

            $new_image_ext = 'jpg';

    

    $info = @GetImageSize($this->source);

    $info = @GetImageSize($this->source);

    }

// What sort of image?

    $mime = $info['mime'];

    $mime = $info['mime'];

   

    $type = substr(strrchr($mime, '/'), 1);

   

   

    if(isSet($this->set_extension)){

    switch ($type){

// What sort of image?

// What sort of image?

        $ext = strrchr($this->source, ".");

        case 'jpeg':

    $type = substr(strrchr($mime, '/'), 1);

    $type = substr(strrchr($mime, '/'), 1);

        $strlen = strlen($ext);

            $image_create_func = 'ImageCreateFromJPEG';

    switch ($type){

    switch ($type){

        $new_name = basename(substr($this->source, 0, -$strlen)).'.'.$new_image_ext;

            $image_save_func = 'ImageJPEG';

        case 'jpeg':

        case 'jpeg':

    }else{

            $new_image_ext = 'jpg';

            $image_create_func = 'ImageCreateFromJPEG';

            $image_create_func = 'ImageCreateFromJPEG';

        $new_name = basename($this->source);

        

            $image_save_func = 'ImageJPEG';

            $image_save_func = 'ImageJPEG';

    }

            // Best Quality: 100

            $new_image_ext = 'jpg';

            $new_image_ext = 'jpg';

   

            $quality = isSet($this->quality) ? $this->quality : 100;

       

       

    $save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;

            break;

            // Best Quality: 100

            // Best Quality: 100

    //输出对象 组成跟$_FILE变量一样 得到后自己和平常图片上传处理一样了

        

            $quality = isSet($this->quality) ? $this->quality : 100;

            $quality = isSet($this->quality) ? $this->quality : 100;

    $img_info['name'] = basename($this->source);

        case 'png':

            break;

            break;

    $img_info['type'] = $mime;

            $image_create_func = 'ImageCreateFromPNG';

       

       

    $img_info['size'] = 1000;

            $image_save_func = 'ImagePNG';

        case 'png':

        case 'png':

    $img_info['tmp_name'] = $save_to;

            $new_image_ext = 'png';

            $image_create_func = 'ImageCreateFromPNG';

            $image_create_func = 'ImageCreateFromPNG';

    $img_info['error'] = 0;

        

            $image_save_func = 'ImagePNG';

            $image_save_func = 'ImagePNG';

       

            // Compression Level: from 0  (no compression) to 9

            $new_image_ext = 'png';

            $new_image_ext = 'png';

    if($method == 'curl'){

            $quality = isSet($this->quality) ? $this->quality : 0;

       

       

        $save_image = $this->LoadImageCURL($save_to);

            break;

            // Compression Level: from 0  (no compression) to 9

            // Compression Level: from 0  (no compression) to 9

    }elseif($method == 'gd'){

        

            $quality = isSet($this->quality) ? $this->quality : 0;

            $quality = isSet($this->quality) ? $this->quality : 0;

        $img = $image_create_func($this->source);

        case 'bmp':

            break;

            break;

   

            $image_create_func = 'ImageCreateFromBMP';

       

       

            if(isSet($quality)){

            $image_save_func = 'ImageBMP';

        case 'bmp':

        case 'bmp':

               $save_image = $image_save_func($img, $save_to, $quality);

            $new_image_ext = 'bmp';

            $image_create_func = 'ImageCreateFromBMP';

            $image_create_func = 'ImageCreateFromBMP';

            }else{

            break;

            $image_save_func = 'ImageBMP';

            $image_save_func = 'ImageBMP';

               $save_image = $image_save_func($img, $save_to);

        

            $new_image_ext = 'bmp';

            $new_image_ext = 'bmp';

            }

        case 'gif':

            break;

            break;

          

            $image_create_func = 'ImageCreateFromGIF';

       

       

    }

            $image_save_func = 'ImageGIF';

        case 'gif':

        case 'gif':

         return $img_info;

            $new_image_ext = 'gif';

            $image_create_func = 'ImageCreateFromGIF';

            $image_create_func = 'ImageCreateFromGIF';

    }

            break;

            $image_save_func = 'ImageGIF';

            $image_save_func = 'ImageGIF';

   

        

            $new_image_ext = 'gif';

            $new_image_ext = 'gif';

    function LoadImageCURL($save_to){

        case 'vnd.wap.wbmp':

 

 

        $ch = curl_init($this->source);

            $image_create_func = 'ImageCreateFromWBMP';

            break;

            break;

        $fp = fopen($save_to, "wb");

            $image_save_func = 'ImageWBMP';

       

       

       

            $new_image_ext = 'bmp';

        case 'vnd.wap.wbmp':

        case 'vnd.wap.wbmp':

        // set URL and other appropriate options

            break;

            $image_create_func = 'ImageCreateFromWBMP';

            $image_create_func = 'ImageCreateFromWBMP';

        $options = array(CURLOPT_FILE => $fp,

        

            $image_save_func = 'ImageWBMP';

            $image_save_func = 'ImageWBMP';

                         CURLOPT_HEADER => 0,

        case 'xbm':

            $new_image_ext = 'bmp';

            $new_image_ext = 'bmp';

                         CURLOPT_FOLLOWLOCATION => 1,

            $image_create_func = 'ImageCreateFromXBM';

            break;

            break;

                         CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)

            $image_save_func = 'ImageXBM';

       

       

       

            $new_image_ext = 'xbm';

        case 'xbm':

        case 'xbm':

        curl_setopt_array($ch, $options);

            break;

            $image_create_func = 'ImageCreateFromXBM';

            $image_create_func = 'ImageCreateFromXBM';

       

        

            $image_save_func = 'ImageXBM';

            $image_save_func = 'ImageXBM';

        curl_exec($ch);

        default:

            $new_image_ext = 'xbm';

            $new_image_ext = 'xbm';

        curl_close($ch);

            $image_create_func = 'ImageCreateFromJPEG';

            break;

            break;

        fclose($fp);

            $image_save_func = 'ImageJPEG';

       

       

 

            $new_image_ext = 'jpg';

        default:

        default:

    }

    }

            $image_create_func = 'ImageCreateFromJPEG';

            $image_create_func = 'ImageCreateFromJPEG';

}

    

            $image_save_func = 'ImageJPEG';

            $image_save_func = 'ImageJPEG';

    if(isSet($this->set_extension)){

            $new_image_ext = 'jpg';

            $new_image_ext = 'jpg';

        $ext = strrchr($this->source, ".");

    }

    }

        $strlen = strlen($ext);

   

   

        $new_name = basename(substr($this->source, 0, -$strlen)).'.'.$new_image_ext;

    if(isSet($this->set_extension)){

    if(isSet($this->set_extension)){

    }else{

        $ext = strrchr($this->source, ".");

        $ext = strrchr($this->source, ".");

        $new_name = basename($this->source);

        $strlen = strlen($ext);

        $strlen = strlen($ext);

    }

        $new_name = basename(substr($this->source, 0, -$strlen)).'.'.$new_image_ext;

        $new_name = basename(substr($this->source, 0, -$strlen)).'.'.$new_image_ext;

    

    }else{

    }else{

    $save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;

        $new_name = basename($this->source);

        $new_name = basename($this->source);

    //输出对象 组成跟$_FILE变量一样 得到后自己和平常图片上传处理一样了

    }

    }

    $img_info['name'] = basename($this->source);

   

   

    $img_info['type'] = $mime;

    $save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;

    $save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;

    $img_info['size'] = 1000;

    //输出对象 组成跟$_FILE变量一样 得到后自己和平常图片上传处理一样了

    //输出对象 组成跟$_FILE变量一样 得到后自己和平常图片上传处理一样了

    $img_info['tmp_name'] = $save_to;

    $img_info['name'] = basename($this->source);

    $img_info['name'] = basename($this->source);

    $img_info['error'] = 0;

    $img_info['type'] = $mime;

    $img_info['type'] = $mime;

        

    $img_info['size'] = 1000;

    $img_info['size'] = 1000;

    if($method == 'curl'){

    $img_info['tmp_name'] = $save_to;

    $img_info['tmp_name'] = $save_to;

        $save_image = $this->LoadImageCURL($save_to);

    $img_info['error'] = 0;

    $img_info['error'] = 0;

    }elseif($method == 'gd'){

       

       

        $img = $image_create_func($this->source);

    if($method == 'curl'){

    if($method == 'curl'){

    

        $save_image = $this->LoadImageCURL($save_to);

        $save_image = $this->LoadImageCURL($save_to);

            if(isSet($quality)){

    }elseif($method == 'gd'){

    }elseif($method == 'gd'){

               $save_image = $image_save_func($img, $save_to, $quality);

        $img = $image_create_func($this->source);

        $img = $image_create_func($this->source);

            }else{

   

   

               $save_image = $image_save_func($img, $save_to);

            if(isSet($quality)){

            if(isSet($quality)){

            }

               $save_image = $image_save_func($img, $save_to, $quality);

               $save_image = $image_save_func($img, $save_to, $quality);

           

            }else{

            }else{

    }

               $save_image = $image_save_func($img, $save_to);

               $save_image = $image_save_func($img, $save_to);

         return $img_info;

            }

            }

    }

          

          

    

    }

    }

    function LoadImageCURL($save_to){

         return $img_info;

         return $img_info;

        $ch = curl_init($this->source);

    }

    }

        $fp = fopen($save_to, "wb");

   

   

        

    function LoadImageCURL($save_to){

    function LoadImageCURL($save_to){

        // set URL and other appropriate options

        $ch = curl_金沙js333娱乐场,init($this->source);

        $ch = curl_init($this->source);

        $options = array(CURLOPT_FILE => $fp,

        $fp = fopen($save_to, "wb");

        $fp = fopen($save_to, "wb");

                         CURLOPT_HEADER => 0,

       

       

                         CURLOPT_FOLLOWLOCATION => 1,

        // set URL and other appropriate options

        // set URL and other appropriate options

                         CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)

        $options = array(CURLOPT_FILE => $fp,

        $options = array(CURLOPT_FILE => $fp,

        

                         CURLOPT_HEADER => 0,

                         CURLOPT_HEADER => 0,

        curl_setopt_array($ch, $options);

                         CURLOPT_FOLLOWLOCATION => 1,

                         CURLOPT_FOLLOWLOCATION => 1,

        

                         CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)

                         CURLOPT_TIMEOUT => 60); // 1 minute timeout (should be enough)

        curl_exec($ch);

       

       

        curl_close($ch);

        curl_setopt_array($ch, $options);

        curl_setopt_array($ch, $options);

        fclose($fp);

       

       

    }

        curl_exec($ch);

        curl_exec($ch);

}

        curl_close($ch);

        curl_close($ch);

        fclose($fp);

        fclose($fp);

 

 

    }

    }

}

}

本文由js333发布于计算机互联网,转载请注明出处:采集远程网站图片保存到本地,采集远程服务器

关键词:

上一篇:没有了

下一篇:没有了