【问题标题】:Cannot resize, then watermark the same image in CodeIgniter无法调整大小,然后在 CodeIgniter 中为同一图像添加水印
【发布时间】:2014-03-23 04:49:00
【问题描述】:

当我尝试做多种事情时,比如调整大小,然后为同一张图片加水印。只有第一个过程 [调整大小] 有效,但第二个无效。

这是我的代码,我将操作分解到一个新库中。

我的控制器:

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;
    }
}

我只是不明白为什么它不能在同一个图像上运行多个操作过程,一个接一个......

【问题讨论】:

    标签: php image codeigniter


    【解决方案1】:

    哇,很奇怪,无论如何,我所要做的就是先给它加水印,然后调整它的大小。我不能反过来做......

    我还必须在 Manipulate_img 类的水印函数中进行更改,

    $this->session->userdata('username') 
    

    把它变成

    $this->CI->session->userdata('username') 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 2018-06-17
      • 2011-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多