Welcome Guest, Not a member yet? Register   Sign In
Cannot resize, then watermark the same image in CodeIgniter
#1

[eluser]therealjerdev[/eluser]
When I try doing multiple things, say resize, then watermark the same image. Only the first process [resizing] works, but the second does not.

here is my code, I factored out the manipulation into a new library.

my controller:

Code:
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();
    }

my library:

Code:
<?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;
    }
}

I just can't get why it wont run multiple manipulation processes on the same image, one after the other...



Messages In This Thread
Cannot resize, then watermark the same image in CodeIgniter - by El Forum - 03-21-2014, 10:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB