用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3202|回复: 8
收起左侧

[已解决] CI图片处理类

[复制链接]
发表于 2013-6-21 15:40:51 | 显示全部楼层 |阅读模式
现在的需求是先将表单中的三个图片上传到服务器,然后呢,再生成3个缩略图,我使用

PHP复制代码
 
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');


但都只能生成一个缩略图,请问该如何解决,谢谢
发表于 2013-6-21 15:45:37 | 显示全部楼层
你不是設了以下的陣列值?
$config['width'] = 40;        
$config['height'] = 40;
 楼主| 发表于 2013-6-21 15:50:37 | 显示全部楼层
Raphael 发表于 2013-6-21 15:45
你不是設了以下的陣列值?
$config['width'] = 40;        
$config['height'] = 40;

我缩略图是生成了,但问题是我有3个上传文件,应该有3个缩略图,可现在指生成一个,找不出原因啊
发表于 2013-6-22 07:27:01 | 显示全部楼层
你尝试打一下log吧,
用log_message('debug', '...');
同时将config.php中的配置打开。
说实话,光看这段代码,貌似没看出什么问题
 楼主| 发表于 2013-6-23 17:27:20 | 显示全部楼层
仙人掌 发表于 2013-6-22 07:27
你尝试打一下log吧,
用log_message('debug', '...');
同时将config.php中的配置打开。

好的,谢谢
发表于 2013-6-24 16:03:07 | 显示全部楼层
aiheguozhi 发表于 2013-6-23 17:27
好的,谢谢

生成第二个图的时候不要调用 $this->load->library() 应该调用 $this->image_lib->initialize()
多看手册吧,可以少走弯路。
 楼主| 发表于 2013-6-28 18:30:36 | 显示全部楼层
Hex 发表于 2013-6-24 16:03
生成第二个图的时候不要调用 $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();  


今天遇到而来同样的问题。不过解决了已经
发表于 2014-5-4 11:50:24 | 显示全部楼层
我用图像类生成缩略图
但是结果是这样的<img style="-webkit-user-select: none" src="http://www.cicms.com/index.php/ecard/createAction">
其中/ecard/createAction只是访问的地我输出了执行前的配置如下
PHP复制代码
[color=#000]Array
(    [image_library] => GD2    [source_image] => D:\xampp\htdocs\CiCMS\www\/data/upload/3-131025151513I84.jpg    [dynamic_output] => 1    [quality] => 50    [wm_vrt_alignment] => top    [wm_hor_alignment] => right    [new_image] => D:\xampp\htdocs\CiCMS\www\data/upload/resize004.gif    [wm_hor_offset] => 20    [wm_vrt_offset] => 30    [wm_text] => 2    [wm_type] => text    [wm_font_size] => 16    [wm_font_color] => ffffff    [wm_padding] => 20 [color=#000])
复制代码


不知道是source_image有问题还是什么,求指点

本版积分规则