/** * Takes a list of image nodes and downloads images checking their * actual dimensions vs. image Node attributes dimensions * * @see checkActualDimsSingle * @param unknown $imgNodes An array of img Nodes * @return ImageLoadResponse An array of ImageLoadResponse Objects */ public static function checkActualDimsThreaded($imgNodes) { $loader = new PageLoad('ImageParserThread.php'); $result = array(); foreach ($imgNodes as $node) { $data = self::getWidthHeight($node); $width = $data[0]; $height = $data[1]; $url = $node->attributes['src']; if (!preg_match('@^https?://@i', $url) && !preg_match('/^data/', $url)) { $url = 'http://' . $node->host . '/' . ltrim($url, '/\\'); } $resp = new ImageLoadResponse(); $resp->htmlWidth = $width; $resp->htmlHeight = $height; $resp->result = self::$BAD; $resp->url = $url; $resp->hash = $node->hash; $resp->actualWidth = -1; $resp->actualHeight = -1; $resp->time = -1; $result[$node->hash] = $resp; $resp->alt = isset($node->attributes['alt']) ? $node->attributes['alt'] : null; $resp->title = isset($node->attributes['title']) ? $node->attributes['title'] : null; //bad image dont need to bother checking if (empty($url) || $width === 0 || $height == 0) { //do nothing //image had the entire http } elseif (preg_match('@^https?://@i', $url)) { $loader->addPage($url, $node->hash, $width, $height); //data type of image } elseif (preg_match('/^data/', $url)) { //data:[<MIME-type>][;charset=<encoding>][;base64],<data> $url = ltrim(strstr($url, ','), ','); $image = imagecreatefromstring($url); $x = imagesx($image); $y = imagesy($image); $resp->result = self::respond($image, $width, $height); $resp->actualWidth = $x; $resp->actualHeight = $y; //no host given } else { $url = 'http://' . $node->host . '/' . ltrim($node->attributes['src'], '/\\'); $loader->addPage($url, $node->hash, $width, $height); } } //get the multithread request response $temp = $loader->exec(); foreach ($temp as $val) { if (empty($val)) { continue; } $resp = new ImageLoadResponse(); $resp->result = $val->result; $resp->url = $val->url; $resp->hash = $val->hash; $resp->htmlWidth = $val->htmlWidth; $resp->htmlHeight = $val->htmlHeight; $resp->actualWidth = $val->actualWidth; $resp->actualHeight = $val->actualHeight; $resp->time = $val->time; $resp->title = $result[$val->hash]->title; $resp->alt = $result[$val->hash]->alt; $result[$val->hash] = $resp; } return $result; }
private function processResponse(&$response, PageLoad &$loader) { if (is_object($response) && isset($response->links) && count($response->links) > 0) { foreach ($response->links as $link) { if (!$this->checkContinue()) { break; } if (!in_array($link, $this->urls)) { array_push($this->urls, $link); $loader->addPage($link, $this->obeyNoFollowTxt); $this->total++; } } } }