views:

21

answers:

0

Hello all,

I am trying to upload an image, put another image over it (like watermark) and save the result in the database, all using Codeigniters image_lib class.

Here's the code:

if ($_FILES['userfile']['error'] == 0 && $_FILES['userfile']['size'] > 0) {
        $uploaddir = "media/";
        $fileName = $_FILES['userfile']['name'];
        $tmpName  = $_FILES['userfile']['tmp_name'];
        $fileSize = $_FILES['userfile']['size'];
        $fileType = $_FILES['userfile']['type'];

        chmod($tmpName, 0777);
        $fp = fopen($tmpName, 'r');

        $content = fread($fp, $fileSize);

        fclose($fp);

        //adding the watermark
        $this->load->library('image_lib');
        $config['source_image'] = $tmpName;
        $config['wm_type'] = "overlay";
        $config['wm_overlay_path'] = "/path_to/profile_pic_overlay.png";
        $config['dynamic_output'] = TRUE;
        $this->image_lib->initialize($config);
        $content = $this->image_lib->watermark();

        //save in the database, 'im' being the Model called earlier
        $this->im->save_image($content, $fileName, $fileType, $fileSize);
}

Doing the above doesn't give me any errors, except that the size of the saved image is 1B.

Thank you!