From 0751c2b3fdd9c7cdb606cead5faeee4a9643f542 Mon Sep 17 00:00:00 2001 From: ycc Date: Tue, 2 Mar 2021 17:11:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/information.php | 3 +++ application/libraries/html_optimize_lib.php | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/application/controllers/information.php b/application/controllers/information.php index fae8a71d..4a3efb66 100644 --- a/application/controllers/information.php +++ b/application/controllers/information.php @@ -497,6 +497,8 @@ class Information extends CI_Controller } else if (strcasecmp($site_code, "ch") == 0 && !empty($auto_update_cache)) { //读取模板生成PC和移动优先文件 $information_new = $this->Information_model->Detail($this->input->post('is_id')); + //设置图片尺寸 + $information_new->ic_content=$this->html_optimize_lib->set_image_size($information_new->ic_content); $this->make_www_cache('mobile', $information_new); $this->make_www_cache('pc', $information_new); } else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) { @@ -578,6 +580,7 @@ class Information extends CI_Controller return false; } if ($this->html_file_helper('find', $information->ic_url)) { + //用于批量更新 //设置图片尺寸 $information->ic_content=$this->html_optimize_lib->set_image_size($information->ic_content); $this->make_www_cache('pc', $information); diff --git a/application/libraries/html_optimize_lib.php b/application/libraries/html_optimize_lib.php index d562c274..b110948a 100644 --- a/application/libraries/html_optimize_lib.php +++ b/application/libraries/html_optimize_lib.php @@ -52,22 +52,24 @@ class html_optimize_lib } } } - + //print_r($request_size); + //print_r($image_sizes); //把尺寸写入html内容中 foreach ($html_object->find('img') as $image) { $img_src = $image->src; if (!empty($image->originalsrc)) { $img_src = $image->originalsrc; } - if(!empty($image_sizes[$img_src])){ - $image->width=$image_sizes[$img_src]->width; - $image->height=$image_sizes[$img_src]->height; + $img_src_urls = parse_url($img_src); + $img_src_index="https://".$img_src_urls['host'] . $img_src_urls['path']; + if(!empty($image_sizes[$img_src_index])){ + $image->width=$image_sizes[$img_src_index]->width; + $image->height=$image_sizes[$img_src_index]->height; } } - return $html_object; + return $html_object->save(); + - //print_r($request_size); - //print_r($image_sizes); }