2010-11-30 50 views
5

目前我正在Zend Framework中的一個巨大的後端應用程序。 很多時候,我最終會使用錯誤的圖標來處理某些對象或動作。PHP代碼來生成圖標

我的問題 是否有任何PHP代碼自動生成圖標????

Ofcourse這些圖標不會神奇地生成,最好的情況是我們有一組圖標,它們的類型是。

  • 對象(用戶,類別,產品,RSS等)
  • 操作(添加,編輯,刪除,更新等)

這樣我們就可以通過混合不同類型的圖標創建圖標蒼蠅。

用於生成圖標以刪除32x32用戶並刪除圖標右下角圖標的代碼。

 
$icon = new Icon(); 
$icon->object('user')->action('delete'); 
$icon->action_align('right')->action_valign('bottom'); 
$icon->action_height(10)->action_width(10); 
$icon->height(32)->width(32); 
$icon->create(); 

這只是一個例子,我們如何創建一個以前從未退出的圖標。

+0

我希望能找到庫正如我所提到或我必須把它寫自己。 – 2010-11-30 09:09:55

+1

我不認爲這裏有一個現有的。但老兄,這是一個不錯的主意! – Shikiryu 2010-11-30 09:22:44

+0

然後我會放棄它。 – 2010-11-30 11:06:36

回答

2

您可以使用GD library來導出圖像,而不是以.ico格式,但.bmp將會正常。用Imagick看來你可以直接執行.ico文件。

2

嘿,我可以建議你這樣一個文件管理器創建:

Filter that creates image thumbnail

<?php 
/** 
* Class for thumbnailing images 
* 
* @author Michał Bachowski ([email protected]) 
* @package JPL 
* @subpackage Jpl_Filter 
* @version 0.1 
* @uses Zend_Filter_Interface, IMagick 
* @license http://framework.zend.com/license/new-bsd  New BSD License 
*/ 
class Jpl_Filter_File_Image_Thumbnail { 
    /** 
    * Thumbnail width 
    * 
    * @var integer 
    */ 
    protected $_width = null; 
    /** 
    * Thumbnail height 
    * 
    * @var integer 
    */ 
    protected $_height = null; 
    /** 
    * Information whether to keep ratio or not while making thumbnail 
    * 
    * @var bool 
    */ 
    protected $_bestFit = true; 
    /** 
    * Information whether crop image or just to resize it 
    * 
    * @var bool 
    */ 
    protected $_crop = false; 
    /** 
    * Method sets destination thumbnail width 
    * 
    * @param integer $width 
    * @return Jpl_Filter_File_Image_Thumbnail 
    */ 
    public function setWidth($width = null) { 
     $this->_width = (int) $width; 
     return $this; 
    } 
    /** 
    * Method sets destination thumbnail height 
    * 
    * @param integer $height 
    * @return Jpl_Filter_File_Image_Thumbnail 
    */ 
    public function setHeight($height = null) { 
     $this->_height = (int) $height; 
     return $this; 
    } 
    /** 
    * Method changes behaviour of filter. 
    * Filter will resize image exactly to given dimensions (false) 
    * or resize image to fit given dimensions but keep original dimension ratio (true). 
    * Setting bestFit to true both dimensions are become mandatory! 
    * 
    * @param bool  $bestFit 
    * @return Jpl_Filter_File_Image_Thumbnail 
    */ 
    public function setBestFit($bestFit = false) { 
     $this->_bestFit = (bool) $bestFit; 
     return $this; 
    } 
    /** 
    * Method changes behaviour of filter. 
    * Filter either just resizes image (false) 
    * or resizes with keeping ratio and crop to best fit given width and height (true) 
    * If true ommits self::$_bestFit attribute! 
    * 
    * @param bool $crop 
    * @return Jpl_Filter_File_Image_Thumbnail 
    */ 
    public function setCrop($crop = false) { 
     $this->_crop = (bool) $crop; 
     return $this; 
    } 
    /** 
    * Method filters given file - makes thumb 
    * 
    * @param string $file path to file 
    * @return string name of file 
    */ 
    public function filter($file) { 
     $im = new IMagick($file); 
     if ($this->_crop) { 
      $im->cropThumbnailImage(
       $this->_width, 
       $this->_height 
      ); 
     } else { 
      $im->thumbnailImage(
       $this->_width, 
       $this->_height, 
       $this->_bestFit 
      ); 
     } 
     $im->writeImage($file); 
    } 
}