喜悦国际村(北京服务器)'s Archiver

firstsmileman 发表于 2008-5-19 11:39 AM

php 上传图片 压缩大小 怎么实现的?

谢谢 ,本人现在特想知道这个问题!

喜悦村会计 发表于 2008-5-19 12:22 PM

你向灾区人民捐款100元,我告诉你怎么实现

firstsmileman 发表于 2008-5-19 12:54 PM

靠  我都捐了

静水流深 发表于 2008-5-19 01:08 PM

貌类要用到某种组件吧?
我也想知道!
期待高手!











[img]http://www.phpx.com/happy/images/common/sigline.gif[/img]
[url=http://www.xing79.com]JokeJoke[/url]

firstsmileman 发表于 2008-5-19 01:14 PM

期待高手指点

niohe 发表于 2008-5-19 01:16 PM

gd2          

firstsmileman 发表于 2008-5-19 01:24 PM

时刻期待着高手指点

firstsmileman 发表于 2008-5-19 02:23 PM

thanks  i got it

奶瓶 发表于 2008-5-19 03:12 PM

GD
[php]
        /**
        * Method resize
        */
        protected function _resize($new_width = 0, $new_height = 0)
        {
                if ($new_width <=0 && $new_height <= 0)
                {
                        // Just copy it
                        @copy($this->source_filename, $this->target_filename);
                        return;
                }
               
                if ($new_width <= 0)
                {
                        $new_width = $new_height * $this->rate;
                }
               
                if ($new_height <= 0)
                {
                        $new_height = $new_width / $this->rate;
                }
               
                $this->target_width = $new_width;
                $this->target_height = $new_height;
               
                $this->_prepare();
               
                imagecopyresized($this->target_gd_obj, $this->source_gd_obj, 0, 0, 0, 0, $this->target_width, $this->target_height, $this->source_width, $this->source_height);
               
                $this->_save();
        }
[/php]

ImageMagick
[php]
        /**
        * Method thumbnail
        * In new version of ImageMagick, this is just like resize, but it's more faster
        */
        protected function _thumbnail($new_width = 0, $new_height = 0)
        {
                $this->target_width = $new_width;
                $this->target_height = $new_height;

                $option = '-thumbnail';
                $param = $new_width . 'x' . $new_height;
                if (!$new_width)
                {
                        $param = 'x' . $new_height;
                }

                if (!$new_height)
                {
                        $param = $new_width;
                }

                $this->cmd = $this->_gen_cmd($option, $param);

                return $this->_exec_cmd();
        }

        /**
        * Generate a command line to execute imagemagick command tool
        */
        protected function _gen_cmd($option, $param = '')
        {
                // Must source and target
                if (!$this->source_filename || !$this->target_filename)
                {
                        return false;
                }

                // "convert" or "mogrify"
                if ($this->source_filename == $this->target_filename)
                {
                        $this->handler = $this->bin_mogrify;
                        $m_flag = true;
                }

                else
                {
                        $this->handler = $this->bin_convert;
                        $m_flag = false;
                }

                $cmd_exec = true_path($this->bin_dir . '/' . $this->handler);
                $cmd = $cmd_exec . (!$m_flag ? (' ' . $this->source_filename . ' ') : ' ') . $option . ' ' . $param . ' ' . $this->target_filename;

                return $cmd;
        }

        /**
        * Execute command
        */
        private function _exec_cmd()
        {
                @exec($this->cmd);
                if (file_exists($this->target_filename))
                {
                        return true;
                }

                return false;
        }
[/php]

MagickWand
[php]
        /**
        * Method resize
        */
        protected function _resize($new_width = 0, $new_height = 0)
        {
                $this->target_width = $new_width;
                $this->target_height = $new_height;

                $rv = MagickReadImage($this->wand_obj, $this->source_filename);
                if (!$rv)
                {
                        return false;
                }

                $rv = MagickResizeImage($this->wand_obj, $new_width, $new_height, MW_TriangleFilter, 1);
                if (!$rv)
                {
                        return false;
                }

                $rv = MagickWriteImage($this->wand_obj, $this->target_filename);

                return $rv;
        }
[/php]

代码片段,剩下的自己看着办

ctrlming 发表于 2008-5-19 04:22 PM

搞点注释吧 真的有些看不懂。

sanders_yao 发表于 2008-5-19 09:53 PM

[quote]原帖由 [i]ctrlming[/i] 于 2008-5-19 04:22 PM 发表
搞点注释吧 真的有些看不懂。 [/quote]
你给奶瓶捐100块钱 我给你翻译注释

ctrlming 发表于 2008-5-19 09:58 PM

他又没受灾。。不给。
奶瓶这个东西是可以把图片伸缩 而不是截取吧?

奶瓶 发表于 2008-5-19 10:33 PM

有人说要截取吗?

ctrlming 发表于 2008-5-19 10:43 PM

我问问 我要收藏不截取的。 thanks

可酷可乐 发表于 2008-5-20 09:55 AM

GD。。好强大。

firstsmileman 发表于 2008-5-20 03:24 PM

thanks! naiping

unspace 发表于 2008-5-20 07:58 PM

有的时候自己想清楚你要做什么

如果你是电脑,你如何分布做

然后去找对应的函数,就可以慢慢解决了

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.