我想用两个函数创建两个不同大小的缩略图.uploadImage()生成大缩略图而uploadIhumb($ name){它在第一个函数内调用}创建小缩略图.第一个功能创建缩略图但第二个不起作用.请解决问题,并突出问题发生的地方?
enter code here:
function uploadImage()
{
$imageName2=$_FILES['file']['tmp_name'];
$config['image_library'] = 'gd2';
//$config['source_image'] = $imageName2;// this is temporary folder where image place on uploading time
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = false;
$config['width'] = 696;
$config['height'] = 241;
$config['new_image'] = 'images/uploads';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$file_name= basename( $imageName2, ".tmp");
$filename=$file_name.'_thumb.tmp';
////////////////////Rename code///////////////////////////
$name= $this->rand_string( 6 );
$dir=$_SERVER['DOCUMENT_ROOT'].'/images/uploads/';
rename($dir . $filename, $dir . $name);
echo $name;
$this->uploadIhumb($name); //FUNCTION CALL
}
function uploadIhumb($name)
{
$config['image_library'] = 'gd2';
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/uploads/'.$name;
$config['create_thumb'] = TRUE;
$config['width'] = 80;
$config['height'] = 80;
$config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'images/uploads/thumbs/';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
Run Code Online (Sandbox Code Playgroud)
不需要任何其他库:-(问题可以解决,如果我们只加载图像库一次,在函数的开始.并且只初始化配置为第二拇指.成功的代码如下运输: -
{function createThumb1($ imageName)//文件名传递{
// this thumbnail created
$config['image_library'] = 'gd2';
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/'.$imageName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = false;
$config['width'] = 80;
$config['height'] = 80;
$config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/uploads/thumbs/'.$imageName;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}
$this->image_lib->clear();
// unable to create this this thumbnail
$config['image_library'] = 'gd2';
$config['source_image'] = $_SERVER['DOCUMENT_ROOT'].'/uploads/'.$imageName;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = false;
$config['width'] = 696;
$config['height'] = 241;
$config['new_image'] = $_SERVER['DOCUMENT_ROOT'].'/images/uploads/'.$imageName;
//$this->load->library('image_lib', $config); // this line cause problem
$this->image_lib->initialize($config); // with this problem resolved
if ( ! $this->image_lib->resize()){echo $this->image_lib->display_errors();}
$this->image_lib->clear();
$this->load->view('admin/upload_form',array('error' => ' ' ));
}
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
3183 次 |
| 最近记录: |