Skip to content

Commit 3a4bbe3

Browse files
committed
改进获取封面大图的类方法
实际生产环境中,发现获取封面大图时获取到了多小尺寸很小的“图标”性质的图片。 改进获取封面大图的类方法,之后可以把一些小图标和小头像之类“图标”性质的图片过滤掉。要么不显示图片,要么显示正文中的尺寸稍大的图片。
1 parent 04e69d9 commit 3a4bbe3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/Readability.inc.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,19 @@ public function getTitle() {
243243
public function getLeadImageUrl($node) {
244244
$images = $node->getElementsByTagName("img");
245245

246-
if ($images->length && $leadImage = $images->item(0)) {
247-
return $leadImage->getAttribute("src");
248-
}
246+
if ($images->length){
247+
$i = 0;
248+
while($leadImage = $images->item($i++)) {
249+
$imgsrc = $leadImage->getAttribute("src");
250+
$imgdatasrc = $leadImage->getAttribute("data-src");
251+
$imgsrclast = $imgsrc ? $imgsrc : $imgdatasrc;
252+
list($img['width'],$img['height'])=getimagesize($imgsrclast);
253+
if($img['width'] > 150 && $img['height'] >150){
254+
return $imgsrclast;
255+
}
256+
257+
}
258+
}
249259

250260
return null;
251261
}

0 commit comments

Comments
 (0)