Skip to content

Commit 06e073a

Browse files
author
明城
authored
Merge pull request #11 from isunman/master
改进获取封面大图的类方法
2 parents 04e69d9 + 3a4bbe3 commit 06e073a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: lib/Readability.inc.php

+13-3
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)