Support and import alt-text supplied by opengraph or image attributes when parsing external links

This commit is contained in:
Mike Macgirvin 2023-12-06 06:47:59 +11:00
parent 27fb8296cd
commit 93f9add9dc

View file

@ -548,6 +548,9 @@ class Linkinfo extends Controller
case "og:image": case "og:image":
$siteinfo["image"] = $attr["content"]; $siteinfo["image"] = $attr["content"];
break; break;
case "og:image:alt":
$siteinfo["image_alt"] = $attr["content"];
break;
case "og:title": case "og:title":
$siteinfo["title"] = $attr["content"]; $siteinfo["title"] = $attr["content"];
break; break;
@ -568,6 +571,7 @@ class Linkinfo extends Controller
} }
$src = self::completeurl($attr["src"], $url); $src = self::completeurl($attr["src"], $url);
$alt = $attr["alt"];
$photodata = @getimagesize($src); $photodata = @getimagesize($src);
if (($photodata) && ($photodata[0] > 150) and ($photodata[1] > 150)) { if (($photodata) && ($photodata[0] > 150) and ($photodata[1] > 150)) {
@ -581,7 +585,9 @@ class Linkinfo extends Controller
} }
$siteinfo["images"][] = ["src" => $src, $siteinfo["images"][] = ["src" => $src,
"width" => $photodata[0], "width" => $photodata[0],
"height" => $photodata[1]]; "height" => $photodata[1],
"alt" => ($alt ?? "")
];
} }
} }
} else { } else {
@ -589,12 +595,17 @@ class Linkinfo extends Controller
unset($siteinfo["image"]); unset($siteinfo["image"]);
$alt = $siteinfo["image_alt"];
unset($siteinfo["image_alt"]);
$photodata = @getimagesize($src); $photodata = @getimagesize($src);
if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10)) { if (($photodata) && ($photodata[0] > 10) and ($photodata[1] > 10)) {
$siteinfo["images"][] = ["src" => $src, $siteinfo["images"][] = ["src" => $src,
"width" => $photodata[0], "width" => $photodata[0],
"height" => $photodata[1]]; "height" => $photodata[1],
"alt" => ($alt ?? '')
];
} }
} }