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...

#2

[eluser]letsgolee[/eluser]
I think there is no font information given. So even though watermark is made there will no text overlayed. Below is the example of font configuration.

Code:
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

#3

[eluser]therealjerdev[/eluser]
[quote author="letsgolee" date="1395490379"]I think there is no font information given. So even though watermark is made there will no text overlayed. Below is the example of font configuration.

Code:
$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '16';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '20';

[/quote]

Hmm, those configs should be already defaulted if not defined by me.
But anyways, I tried it anyways and it still wont work.
My code seems pretty logical to you right? Can't seem to see why it won't work out.. :/

My thinking is that the second process [watermarking] gets executed before the last one was fully saved to disk, but that shouldn't be the case because php should wait for a return [true] from the resize method called. and since it does, the image should have already been saved to disk.. which in turn would go to the next 'watermarking'...
#4

[eluser]therealjerdev[/eluser]
Wow, weird, anyways, all I had to do was watermark it first, and THEN resize it. I couldn't do it the other way around which was weird...

I also had to change, within the watermark function in my Manipulate_img class,
Code:
$this->session->userdata('username')
and turn it into
Code:
$this->CI->session->userdata('username')




Theme © iAndrew 2016 - Forum software by © MyBB