Codeigniter 编码器点火器图像缩略图问题
我想用两个功能创建两个大小不同的缩略图。 上传图像() 上传时生成大缩略图($name){它在第一个函数内调用}创建小缩略图。 第一个函数创建缩略图,但第二个函数不起作用。 请解决问题并突出显示问题发生的位置Codeigniter 编码器点火器图像缩略图问题,codeigniter,Codeigniter,我想用两个功能创建两个大小不同的缩略图。 上传图像() 上传时生成大缩略图($name){它在第一个函数内调用}创建小缩略图。 第一个函数创建缩略图,但第二个函数不起作用。 请解决问题并突出显示问题发生的位置 enter code here: function uploadImage() { $imageName2=$_FILES['file']['tmp_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();
}
尝试使用以下命令清除函数顶部的配置:
$this->image_lib->clear();
此外,您还可以使用以下方法检查任何错误:
if ( ! $this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
希望这有帮助。不需要任何其他库:-( 若我们在函数开始时只加载一次图像库,那个么这个问题就可以得到解决。 并且仅初始化了第二个thumb的配置。成功代码如下:- { 函数createThumb1($imageName)//传递了文件名 {
}嘿,谢谢你的回答 是的,这是最后制作的作品 $this->image_lib->clear() 及 为了第二个thambnail //$this->load->library('image_lib',$config) 注释掉第一行并替换为第二行。
您的查询将得到解决。尊敬的先生;出现以下错误:-您的服务器不支持处理此类映像所需的GD功能。您是否具有目录的写入权限?您还可以尝试将“$config['image\u library']='gd2';”更改为“$config['image\u library']='GD'”。此外,请确保“source\u image”和“new_image”位置正确…您尝试上载的图像格式是什么?它是否适用于jpeg图像?我正在使用Localhost;也使用了$config['image_library']='GD';但出现了相同的错误。我想您可能在“new_image”开头缺少正斜杠“…应该是“/images/uploads/thumbs/”?如果你不添加新内容,请不要恢复旧帖子。
// 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' => ' ' ));
}
$this->image_lib->initialize($config);