本文整理汇总了PHP中ImageHandler::DownloadImage方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageHandler::DownloadImage方法的具体用法?PHP ImageHandler::DownloadImage怎么用?PHP ImageHandler::DownloadImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageHandler
的用法示例。
在下文中一共展示了ImageHandler::DownloadImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addImageFromUrl
/**
* Add an image to the file.
*
* @param string $url Url to the image
*
* @return int The reference of the image, false if the image couldn't be downloaded
*/
public function addImageFromUrl($url)
{
$image = ImageHandler::DownloadImage($url);
if ($image === false) {
return false;
}
return $this->addImage($image);
}
示例2: handleImages
/**
*
* @param DOMElement $dom
* @return array
*/
private function handleImages($dom, $url)
{
$images = array();
$parts = parse_url($url);
$savedImages = array();
$imgElements = $dom->getElementsByTagName('img');
foreach ($imgElements as $img) {
$src = $img->getAttribute("src");
$is_root = false;
if (substr($src, 0, 1) == "/") {
$is_root = true;
}
$parsed = parse_url($src);
if (!isset($parsed["host"])) {
if ($is_root) {
$src = http_build_url($url, $parsed, HTTP_URL_REPLACE);
} else {
$src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH);
}
}
$img->setAttribute("src", "");
if (isset($savedImages[$src])) {
$img->setAttribute("recindex", $savedImages[$src]);
} else {
$image = ImageHandler::DownloadImage($src);
if ($image !== false) {
$images[$this->imgCounter] = new FileRecord(new Record($image));
$img->setAttribute("recindex", $this->imgCounter);
$savedImages[$src] = $this->imgCounter;
$this->imgCounter++;
}
}
}
return $images;
}
示例3: setData
/**
* Set the data to use
* @param string $data Data to put in the file
*/
public function setData($data)
{
//$data = utf8_encode($data);
$data = CharacterEntities::convert($data);
//$data = utf8_decode($data);
//$this->source = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $data);
$images = array();
// image handling stuff
$dom = new DOMDocument();
$dom->loadHTML($data) or die($data);
$dom->normalizeDocument();
//exit();
$savedImages = array();
$imgElements = $dom->getElementsByTagName('img');
foreach ($imgElements as $img) {
$src = $img->getAttribute("src");
$is_root = false;
if (substr($src, 0, 1) == "/") {
$is_root = true;
}
/*$parsed = parse_url($src);
if(!isset($parsed["host"])){
if($is_root){
$src = http_build_url($url, $parsed, HTTP_URL_REPLACE);
}else{
$src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH);
}
}*/
$img->setAttribute("src", "");
if (isset($savedImages[$src])) {
$img->setAttribute("recindex", $savedImages[$src]);
} else {
$image = ImageHandler::DownloadImage($src);
if ($image !== false) {
$images[$this->imgCounter] = new FileRecord(new Record($image));
$img->setAttribute("recindex", $this->imgCounter);
$savedImages[$src] = $this->imgCounter;
$this->imgCounter++;
}
}
}
$this->images = $images;
//end image stuff
$data = $dom->saveXML();
$data = str_replace("<pagebreak/>", "<mbp:pagebreak/>", $data);
$data = str_replace("<pagebreak></pagebreak>", "<mbp:pagebreak/>", $data);
// echo $data;
// print_r($this->images);
$this->source = $data;
$this->prc = false;
}