示例#1
0
文件: Image.php 项目: emijrp/Peachy
 /**
  * Downloads an image to the local disk
  *
  * @param string $localname Filename to store image as. Default null.
  * @param int $width Width of image to download. Default -1.
  * @param int $height Height of image to download. Default -1.
  * @return void
  */
 public function download($localname = null, $width = -1, $height = -1)
 {
     global $pgIP;
     if (!$this->get_exists()) {
         pecho("Attempted to download a non-existant file.", PECHO_NOTICE);
     }
     $ii = $this->imageinfo(1, $width, $height);
     if (is_array($ii)) {
         $ii = $ii[0];
         if ($width != -1) {
             $url = $ii['thumburl'];
         } else {
             $url = $ii['url'];
         }
         if (is_null($localname)) {
             $localname = $pgIP . 'Images/' . $this->localname;
         }
         Hooks::runHook('DownloadImage', array(&$url, &$localname));
         pecho("Downloading {$this->title} to {$localname}..\n\n", PECHO_NOTICE);
         $this->wiki->get_http()->download($url, $localname);
     } else {
         pecho("Error in getting image URL.\n\n" . print_r($ii) . "\n\n", PECHO_FATAL);
     }
 }