iwind的专栏

iwind - 匆匆人生中,你做了几件令自己骄傲的事呢?

章节ID:ccterran
22644次访问,排名5023好友1人,关注者1
ccterran的文章
原创 23 篇
翻译 0 篇
转载 0 篇
评论 8 篇
iwind的公告
本blog皆为iwind原创或翻译,转载时最好写上出处。

我的日记

我的其它常用名:ccterran,month,coldwind

最近评论
fftaks:Wow gold
vanxining:很不错。
mark:语言通俗简明。good!
study:谢谢你。我在你这里学了好多东西。解决了我很多疑问!
谢谢!
寻梦人:非常不错.正愁资料呢,谢谢
文章分类
收藏
    相册
    PHP人
    IWIND(RSS)
    PHP艺术
    个人日记
    PEAR中文
    我的日记(RSS)
    技术资源
    ADODB
    PEAR
    PHP.NET
    SF.NET
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 图片的分割与组合收藏

    新一篇: PHPLIB Template入门系列 - 1 简介 | 旧一篇: JS基础 -- 书写JScript代码

    我这里只考虑jpg,gif,png格式.

    <?php
    /**
      * @author iwind iwind@wangyou.com.cn
      */   
    class Image
    {
        var
    $ext;
        var
    $i_ext;
        var
    $width;
        var
    $height;
        var
    $create_func;
        var
    $out_func;

        function
    image_load($files)
        {
            
    $file = (is_array($files))?$files[0]:$files;
            
    $info = getimagesize($file);
            switch (
    $info[2])
            {
                case
    "1":
                    
    $this->ext = "gif";
                    
    $this->i_ext = "gif";
                    break;
                case
    "2":
                    
    $this->ext = "jpg";
                    
    $this->i_ext = "jpeg";
                    break;
                case
    "3":
                    
    $this->ext = "png";
                    
    $this->i_ext = "png";
                    break;
                default:
                    
    $this->ext = "jpg";
                    
    $this->i_ext = "jpeg";
            }
            
    $this->create_func = "imagecreatefrom" . $this->i_ext;
            
    $this->out_func = "image" . $this->i_ext;
            
    $this->width = $info[0];
            
    $this->height = $info[1];
        }

        function
    image_split($photo, $x_num=1, $y_num=1)
        {
            
    $this->image_load($photo);
            eval(
    "\$im=" . $this->create_func . "(\$photo);");
            
    $x_width = $this->width/$x_num;
            
    $y_height = $this->height/$y_num;
            
    $im1 = imagecreate($x_width, $y_height);
            
    $files = array();
            for (
    $i=0; $i<$x_num; $i++)
            {
                 for (
    $j=0; $j<$y_num; $j++)
                {
                    
    $x = $i * $x_width;
                    
    $y = $j * $y_height;
                    
    imagecopyresampled($im1, $im, 0, 0, $x, $y, $x_width, $y_height, $x_width, $y_height);
                    
    $new_file = "{$i}_{$j}.{$this->ext}";
                    
    $files[] = $new_file;
                    eval(
    "{$this->out_func}(\$im1, \$new_file);");
                }
            }
            
    imagedestroy($im1);
            return
    $files;
        }

        function
    image_join($files, $new_file)
        {
            if (!empty(
    $files))
            {
                
    $this->image_load($files);
                
    $i_arr = array();
                
    $j_arr = array();
                foreach (
    $files as $v)
                {
                    list(
    $v1) = explode(".", $v);
                    list(
    $i_arr[], $j_arr[]) = explode("_", $v1);
                }
                
    $i_arr = array_unique($i_arr);
                
    $j_arr = array_unique($j_arr);
                
    $x_num = count($i_arr);
                
    $y_num = count($j_arr);
                
    $im1 = imagecreate($x_num * $this->width, $y_num * $this->height);
                foreach (
    $i_arr as $i)
                {
                    foreach (
    $j_arr as $j)
                    {
                        
    $x = $i * $this->width;
                        
    $y = $j * $this->height;
                        eval(
    "\$im = {$this->create_func}(" . "\"{$i}_{$j}.{$this->ext}\");");
                        
    imagecopyresampled($im1, $im, $x, $y, 0, 0, $this->width, $this->height, $this->width, $this->height);
                    }
                }
                eval(
    "{$this->out_func}(\$im1, \$new_file);");
            }
        }
    }

    //创建一个实例
    $img = new image();

    //将 20041099024319.jpg 分成 2 * 3部分,即宽两部分,高三部分
    //$files 是文件名数组
    $files = $img->image_split("20041099024319.jpg", 2 , 3);

    //将分成的小图重新组起来,名称为 new.jpg
    $img->image_join($files, "new.jpg");

    //
    echo "success......";
    ?>

    发表于 @ 2004年10月31日 11:52:00|评论(loading...)|编辑

    新一篇: PHPLIB Template入门系列 - 1 简介 | 旧一篇: JS基础 -- 书写JScript代码

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © iwind