]>
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 if (defined('NO_CURL') ||
!function_exists("curl_init"))
24 $charset_hack = '<head>
25 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
28 $doc = new DOMDocument();
29 $doc->loadHTML($charset_hack . $article["content"]);
34 $xpath = new DOMXpath($doc);
36 $images = $xpath->query('(//img[@src])');
38 foreach ($images as $img) {
39 $src = $img->getAttribute("src");
41 $ch = curl_init($src);
42 curl_setopt($ch, CURLOPT_HEADER
, 0);
43 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, 1);
44 curl_setopt($ch, CURLOPT_BINARYTRANSFER
,1);
45 curl_setopt($ch, CURLOPT_RANGE
, "0-32768");
47 @$result = curl_exec($ch);
48 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE
);
50 if ($result && ($http_code == 200 ||
$http_code == 206)) {
51 $filename = tempnam(sys_get_temp_dir(), "ttsizecheck");
54 $fh = fopen($filename, "w");
59 @$info = getimagesize($filename);
61 if ($info && $info[0] > 0 && $info[1] > 0) {
62 $img->setAttribute("width", $info[0]);
63 $img->setAttribute("height", $info[1]);
74 $doc->removeChild($doc->firstChild
); //remove doctype
75 $article["content"] = $doc->saveHTML();
84 function api_version() {