|
|
|
@ -23,7 +23,7 @@ class html_optimize_lib
|
|
|
|
|
|
|
|
|
|
//获取图片尺寸
|
|
|
|
|
public function set_image_size($html)
|
|
|
|
|
{return $html;
|
|
|
|
|
{
|
|
|
|
|
$html_object = str_get_html($html);
|
|
|
|
|
|
|
|
|
|
//拼接图片链接,获取尺寸
|
|
|
|
@ -33,9 +33,10 @@ class html_optimize_lib
|
|
|
|
|
if (!empty($image->originalsrc)) {
|
|
|
|
|
$img_src = $image->originalsrc;
|
|
|
|
|
}
|
|
|
|
|
if (strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false) {//以data或者images开头的域名才能获取尺寸
|
|
|
|
|
//图片已经设置了尺寸的不再修改
|
|
|
|
|
if (empty($image->width) && strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false) {//以data或者images开头的域名才能获取尺寸
|
|
|
|
|
$img_src_urls = parse_url($img_src);
|
|
|
|
|
$request_size[$img_src_urls['host']][] = $img_src_urls['path'];
|
|
|
|
|
$request_size[$img_src_urls['host']][] =$img_src_urls['path'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -47,7 +48,7 @@ class html_optimize_lib
|
|
|
|
|
if (!empty($size_data)) {
|
|
|
|
|
$size_data = json_decode($size_data);
|
|
|
|
|
foreach ($size_data as $size_item) {
|
|
|
|
|
$size_item->photo = "https://{$host}" . $size_item->photo;
|
|
|
|
|
$size_item->photo = "https://".$host . $size_item->photo;//这个作为索引,找到对应url的尺寸
|
|
|
|
|
$image_sizes[$size_item->photo] = $size_item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -60,12 +61,16 @@ class html_optimize_lib
|
|
|
|
|
if (!empty($image->originalsrc)) {
|
|
|
|
|
$img_src = $image->originalsrc;
|
|
|
|
|
}
|
|
|
|
|
$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;
|
|
|
|
|
//图片已经设置了尺寸的不再修改
|
|
|
|
|
if (empty($image->width) && strpos($img_src, '//data.') !== false || strpos($img_src, '//images.') !== false) {//以data或者images开头的域名才能获取尺寸
|
|
|
|
|
$img_src_urls = parse_url($img_src);
|
|
|
|
|
$img_index="https://".$img_src_urls['host'] . $img_src_urls['path'];
|
|
|
|
|
if(!empty($image_sizes[$img_index])){
|
|
|
|
|
$image->width=$image_sizes[$img_index]->width;
|
|
|
|
|
$image->height=$image_sizes[$img_index]->height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return $html_object->save();
|
|
|
|
|
|
|
|
|
|