当我尝试做多件事时,请说调整大小,然后为同一图像添加水印。只有第一个进程[resizing]有效,但第二个进程没有。
这是我的代码,我将操作分解为新库。
我的控制员:
function upload()
{
// start jpegcam code
$username = $this->session->userdata('username');
if (!file_exists(APPPATH . '../images/' . $username . '/'))
{
mkdir(APPPATH . '../images/' . $username . '/', 0777, true);
}
$folder = APPPATH . '../images/' . $username . '/';
$filename = $this->session->userdata('username') . date("-Ymd") . '.jpg';
$input_con = file_get_contents("php://input");
$image_data = $folder.$filename;
file_put_contents($image_data, $input_con);
//end jpegcam code
/* Start image manipulation
* Start resizing to 640px x 480px
*/
$this->load->library('manipulate_img');
$this->manipulate_img->resize($image_data);
/*
* Start watermarking date/time and logo
*/
$this->manipulate_img->watermark($image_data);
//if (isset($_POST))
// $this->Gallery_model->do_upload();
}
我的图书馆:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Manipulate_img
{
function __construct()
{
$this->CI =& get_instance();
$this->CI->load->library('image_lib');
}
public function resize($pic_path)
{
/*
* Start resizing to 640px x 480px
*/
$config['source_image'] = $pic_path;
$config['maintain_ratio'] = TRUE;
$config['width'] = 640;
$config['height'] = 480;
$this->CI->image_lib->initialize($config);
$this->CI->image_lib->resize();
$this->CI->image_lib->clear();
return true;
}
public function watermark($pic_path)
{
$config['source_image'] = $pic_path;
$config['wm_text'] = date("F m Y // ") . $this->session->userdata('username') . ' // www.InterJo.in';
$this->CI->image_lib->initialize($config);
$this->CI->image_lib->watermark();
$this->CI->image_lib->clear();
return true;
}
}
我无法理解为什么它不会在同一张图片上运行多个操作过程,一个接一个......
答案 0 :(得分:0)
我还必须在Manipulate_img类的水印函数中更改
$this->session->userdata('username')
并将其转换为
$this->CI->session->userdata('username')