生成图标的 PHP 代码

发布于 2024-10-04 23:16:44 字数 590 浏览 0 评论 0原文

目前我正在 Zend Framework 中开发一个巨大的后端应用程序。 很多时候我最终会为某些对象或操作使用错误的图标。

我的问题 有没有自动生成图标的php代码???

当然这些图标不会神奇地生成,最好的情况是我们有一个类型为 的图标集合。

  • 对象(用户、类别、产品、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();

这只是一个例子,说明我们如何创建一个以前从未退出过的图标。

currently i am working on a huge back-end application in Zend Framework.
A lot of times i end up using wrong icon for some object or action.

My Question
Is there any php code to generate icons automatically????

Ofcourse these icons will not be generated magically, best case scenario is that we have a collection of icons which have the type of.

  • Object (user,category,product,rss etc)
  • Action (add,edit,delete,update etc)

This way we can create icons by mixing different types of icons on the fly.

The code for generating a icon to delete user with 32x32 and delete icon in bottom-right corner of the icon.

$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();

This is just an example that how can we create a icon which was never exited before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独享拥抱 2024-10-11 23:19:21

嘿,我可以建议您创建这样的文件管理器:

创建图像缩略图的过滤器

<?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 );
    }
}

Hey i can suggest you to create filer like this one :

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 );
    }
}
北渚 2024-10-11 23:19:17

您可以使用GD库导出图像,不是.ico格式,而是.bmp 就可以了。使用 Imagick 似乎你可以直接处理 .ico 文件。

You can use GD library to export the images, not in the .ico format but a .bmp will be ok. With Imagick it seems you can do directly .ico files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文