當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImageHandler::DownloadImage方法代碼示例

本文整理匯總了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);
 }
開發者ID:wallabag,項目名稱:php-mobi,代碼行數:15,代碼來源:MultipleFileHandler.php

示例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;
 }
開發者ID:master3395,項目名稱:CBPPlatform,代碼行數:40,代碼來源:OnlineArticle.php

示例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;
 }
開發者ID:smelzo,項目名稱:PHP-Digital-Format-Convert-Epub-Mobi-PDF,代碼行數:56,代碼來源:Mobi.inc.php


注:本文中的ImageHandler::DownloadImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。