]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_zz_imgsetsizes/init.php
2 class Af_Zz_ImgSetSizes
extends Plugin
{
7 "Set width/height attributes for images in articles (requires CURL and GD)",
11 function init($host) {
14 if (function_exists("curl_init") && function_exists("getimagesize")) {
15 $host->add_hook($host::HOOK_ARTICLE_FILTER
, $this);
19 function hook_article_filter($article) {
21 $owner_uid = $article["owner_uid"];
23 $charset_hack = '<head>
24 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
27 $doc = new DOMDocument();
28 $doc->loadHTML($charset_hack . $article["content"]);
33 $xpath = new DOMXpath($doc);
35 $images = $xpath->query('(//img[@src])');
37 foreach ($images as $img) {
38 $src = $img->getAttribute("src");
40 $ch = curl_init($src);
41 curl_setopt($ch, CURLOPT_HEADER
, 0);
42 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
43 curl_setopt($ch, CURLOPT_BINARYTRANSFER
,1);
44 curl_setopt($ch, CURLOPT_RANGE
, "0-32768");
46 @$result = curl_exec($ch);
47 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE
);
49 if ($result && ($http_code == 200 ||
$http_code == 206)) {
50 $filename = tempnam(sys_get_temp_dir(), "ttsizecheck");
53 $fh = fopen($filename, "w");
58 @$info = getimagesize($filename);
60 if ($info && $info[0] > 0 && $info[1] > 0) {
61 $img->setAttribute("width", $info[0]);
62 $img->setAttribute("height", $info[1]);
73 $doc->removeChild($doc->firstChild
); //remove doctype
74 $article["content"] = $doc->saveHTML();
83 function api_version() {