Ejemplo n.º 1
0
 /**
  * 生成图像
  *
  * @param  string  $phrase
  * @return resource
  * @throws Exception
  */
 public function generateImage($phrase = null)
 {
     null == $phrase && ($phrase = $this->generatePhrase());
     extract($this->_options);
     //解出参数到变量
     $image = $this->_createImage();
     //创建图像
     $defaultSize = min($width, $height * 2) / (strlen($phrase) + 1);
     $spacing = (int) ($width * 0.9 / strlen($phrase));
     empty($fonts) && ($fonts = YUN_Io::scan(strip($fontDir)));
     if (empty($fonts)) {
         throw new Exception('未找到任何有效的字体文件');
     }
     for ($i = 0, $strlen = strlen($phrase); $i < $strlen; $i++) {
         $font = $fontDir . '/' . $fonts[array_rand($fonts)];
         $color = imagecolorallocate($image, mt_rand(0, 160), mt_rand(0, 160), mt_rand(0, 160));
         $angle = mt_rand(-30, 30);
         $size = $defaultSize / 10 * mt_rand(12, 14);
         $box = imageftbbox($size, $angle, $font, $phrase[$i]);
         $x = $spacing / 4 + $i * $spacing + 2;
         $y = $height / 2 + ($box[2] - $box[5]) / 4;
         imagefttext($image, $size, $angle, $x, $y, $color, $font, $phrase[$i]);
     }
     $this->_image = $image;
     return $this->_image;
 }
Ejemplo n.º 2
0
 /**
  * 删除分类
  * @param  integer  $cateId
  * @throws Exception
  */
 public function cateDel($cateId)
 {
     $where = $this->db->quoteInto('cate_id=?', $cateId);
     $cateInfo = $this->cateInfoSql($where);
     if (empty($cateInfo)) {
         throw new Exception('指定的分类不存在');
     }
     if (!$cateInfo['allow_delete']) {
         throw new Exception('该分类被设置为禁止删除');
     }
     $abspath = $this->fileBasePath . "/" . $cateInfo['filepath'];
     if (is_dir($abspath)) {
         $files = YUN_Io::scan($abspath);
         if (!empty($files)) {
             throw new Exception('分类目录不为空,无法删除');
         }
         rmdir($abspath);
     }
     $this->db->delete('file_category', $where);
     $this->db->delete('file', $where);
 }