我正在使用CodeIgniter v3.1.6。我的项目目录结构如下:
-application
-assets
-system
........
我想调整原来位于assets/admin/uploads/editionpages_img
的图片尺寸(939128_1523936489.jpg)
我的调整大小代码如下:
function __construct()
{
$this->load->library('image_lib');
$this->load->helper("url");
$this->load->helper('form');
}
public function resize()
{
$imgName ='939128_1523936489';
$config['image_library'] = 'gd2';
$config['source_image'] = './assets/admin/uploads/editionpages_img/'.$imgName.".jpg";
$config['new_image'] = './assets/admin/uploads/editionpages_img/'.$imgName."_new.jpg";
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
}
运行此代码时,不会显示任何错误,也不会在上述位置创建任何已调整大小的图像。请告知我的代码有什么问题。谢谢。
答案 0 :(得分:1)
希望这能解决您的问题
注意:包含图像文件的文件夹必须具有写入权限。
首先:从构造函数方法
中删除image_lib
function __construct()
{
$this->load->helper("url");
$this->load->helper('form');
}
第二:在FCPATH
方法
resize()
你的方法应该是这样的:
public function resize()
{
$imgName ='939128_1523936489';
$config['image_library'] = 'gd2';
$config['source_image'] = FCPATH.'assets/admin/uploads/editionpages_img/'.$imgName.".jpg";
$config['new_image'] = FCPATH.'assets/admin/uploads/editionpages_img/'.$imgName."_new.jpg";
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 50;
$config['height'] = 50;
$this->load->library('image_lib', $config);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
}
更多信息:https://www.codeigniter.com/user_guide/libraries/image_lib.html