aiheguozhi 发表于 2013-6-21 15:40:51

CI图片处理类

现在的需求是先将表单中的三个图片上传到服务器,然后呢,再生成3个缩略图,我使用


private function resizePhoto($source_image) {
                $config['image_library'] = 'gd2';
                $config['source_image'] = $source_image;
                $config['create_thumb'] = TRUE;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 40;
                $config['height'] = 40;
                $this->load->library('image_lib', $config);
                $result = $this->image_lib->resize();               
      }

循环调用这个方法,把三个原图的地址传给这个方法,但最终至生成了一个缩略图,请问是什么原因呢?

我已经尝试把循环改成如下方式调用:
$this->resizePhoto('/home/zhuding/public_html/apps/uploads/DSC04468.JPG');                $this->resizePhoto('/home/zhuding/public_html/apps/uploads/DSC04469.JPG');                $this->resizePhoto('/home/zhuding/public_html/apps/uploads/DSC04465.JPG');

但都只能生成一个缩略图,请问该如何解决,谢谢

Raphael 发表于 2013-6-21 15:45:37

你不是設了以下的陣列值?
$config['width'] = 40;      
$config['height'] = 40;

aiheguozhi 发表于 2013-6-21 15:50:37

Raphael 发表于 2013-6-21 15:45 static/image/common/back.gif
你不是設了以下的陣列值?
$config['width'] = 40;      
$config['height'] = 40;

我缩略图是生成了,但问题是我有3个上传文件,应该有3个缩略图,可现在指生成一个,找不出原因啊

仙人掌 发表于 2013-6-22 07:27:01

你尝试打一下log吧,
用log_message('debug', '...');
同时将config.php中的配置打开。
说实话,光看这段代码,貌似没看出什么问题

aiheguozhi 发表于 2013-6-23 17:27:20

仙人掌 发表于 2013-6-22 07:27 static/image/common/back.gif
你尝试打一下log吧,
用log_message('debug', '...');
同时将config.php中的配置打开。


好的,谢谢

Hex 发表于 2013-6-24 16:03:07

aiheguozhi 发表于 2013-6-23 17:27 static/image/common/back.gif
好的,谢谢

生成第二个图的时候不要调用 $this->load->library() 应该调用 $this->image_lib->initialize()
多看手册吧,可以少走弯路。

aiheguozhi 发表于 2013-6-28 18:30:36

Hex 发表于 2013-6-24 16:03 static/image/common/back.gif
生成第二个图的时候不要调用 $this->load->library() 应该调用 $this->image_lib->initialize()
多看手册 ...

好的,谢谢

给你晴天般的微 发表于 2013-8-7 11:08:39

$this->load->library('image_lib');
$this->image_lib->initialize($config);
   $res = $this->image_lib->resize();


今天遇到而来同样的问题。不过解决了已经

0day_You 发表于 2014-5-4 11:50:24

我用图像类生成缩略图
但是结果是这样的<img style="-webkit-user-select: none" src="http://www.cicms.com/index.php/ecard/createAction">
其中/ecard/createAction只是访问的地我输出了执行前的配置如下
Array
(    => GD2    => D:\xampp\htdocs\CiCMS\www\/data/upload/3-131025151513I84.jpg    => 1    => 50    => top    => right    => D:\xampp\htdocs\CiCMS\www\data/upload/resize004.gif    => 20    => 30    => 2    => text    => 16    => ffffff    => 20 )

不知道是source_image有问题还是什么,求指点
页: [1]
查看完整版本: CI图片处理类