Welcome Guest, Not a member yet? Register   Sign In
Watermark
#1

[eluser]Sanity11[/eluser]
Hi all,

I want to upload a image and immediately create a copy with a watermark.

First I want to get the watermarking working:

Code:
function do_upload()
    {
        $data = $this->od_model->general();
        
        $config['upload_path'] = './images/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '200';
        $config['max_width']  = '1024';
        $config['max_height']  = '1280';
        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload())
        {
            $upload_info = array('error' => $this->upload->display_errors());
            
            $this->images($upload_info);
        }    
        else
        {    
            $upload_info = array('upload' => $this->upload->data());
            
            $this->od_model->insert_image_data($upload_info['upload']['file_name']);
            
            //Maak na de upload direct de afbeelding met het watermerk aan.
            $this->load->library('image_lib');
            
            $config_wat['source_image'] = $data['uploaded_images_path'] . $upload_info['upload']['file_name'];
            $config_wat['wm_text'] = 'VERKOCHT!';
            $config_wat['wm_type'] = 'text';
            $config_wat['wm_font_path'] = $data['base_system_url'] . 'fonts/texb.ttf';
            $config_wat['wm_font_size'] = '40';
            $config_wat['wm_font_color'] = 'ff0000';
            $config_wat['wm_vrt_alignment'] = 'center';
            $config_wat['wm_hor_alignment'] = 'center';
            $config_wat['wm_padding'] = '20';
            
            $this->image_lib->initialize($config_wat);
            
            $this->image_lib->watermark();
            
            //Als alles klaar is wordt de functie images aageroepen. Deze herlaadt de pagina zodat de updates zichtbaar zijn.
            $this->images($upload_info);
        }
    }

This code makes the image upload perfectly. But there is no watermark..? Can someone help me identify the problem?
#2

[eluser]TheFuzzy0ne[/eluser]
I recommend you check to see if the watermarking was successful, and printing the error message if it's not. It might give yu a clue as to what's going on.

Code:
...

if ( ! $this->image_lib->watermark())
{
    echo $this->image_lib->display_errors();
}

I think this is how it's meant to be written in the user guide, as the examples for crop, rotate and resize are written in a similar fashion.
#3

[eluser]Sanity11[/eluser]
Thanks, I was just doing that like this:

Code:
function do_upload()
    {
        $data = $this->od_model->general();
        
        $config['upload_path'] = './images/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '200';
        $config['max_width']  = '1024';
        $config['max_height']  = '1280';
        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload())
        {
            $upload_info = array('error' => $this->upload->display_errors());
            
            $this->images($upload_info);
        }    
        else
        {    
            $upload_info = array('upload' => $this->upload->data());
            
            $this->od_model->insert_image_data($upload_info['upload']['file_name']);
            
            $this->load->library('image_lib');
        
            $config_wm['source_image'] = $data['uploaded_images_path'] . $upload_info['upload']['file_name'];
            $config_wm['wm_type'] = 'text';
            $config_wm['wm_text'] = 'VERKOCHT!';
            $config_wm['wm_font_path'] = $data['base_system_url'] . 'fonts/texb.ttf';
            $config_wm['wm_font_size'] = '40';
            $config_wm['wm_font_color'] = 'ff0000';
            $config_wm['wm_vrt_alignment'] = 'bottom';
            $config_wm['wm_hor_alignment'] = 'center';
            $config_wm['wm_padding'] = '20';
            $config_wm['dynamic_output'] = FALSE;
            $config_wm['create_thumb'] = FALSE;
        
            $this->image_lib->initialize($config_wm);
        
            $this->image_lib->watermark();
            
            if (! $this->image_lib->watermark())
            {
                $upload_info = array('wm_info' => $this->image_lib->display_errors(), 'path' => $data['uploaded_images_path'] . $upload_info['upload']['file_name']);
                $this->images($upload_info);
            }
            else
            {
                //Als alles klaar is wordt de functie images aageroepen. Deze herlaadt de pagina zodat de updates zichtbaar zijn.
                $upload_info = array('wm_info' => $this->image_lib->data());
                $this->images($upload_info);
            }
        }
    }

This results in the following messages:



*

The path to the image is not correct.

Your server does not support the GD function required to process this type of image.

Your server does not support the GD function required to process this type of image.
* http://www.outletdieze.nl/images/uploads...uct_28.jpg


I have outputted the path and it's correct. I am also sure this server is capable of watermarking (i have a expression engine site running with watermarking functionality.)

Strange.
#4

[eluser]TheFuzzy0ne[/eluser]
What version of PHP are you running? I'm sure PHP 5 comes with GD2 as standard, although I'm sure it's possible to compile it without, or though I don't see why you'd want to.

Have you tried ImageMagick? You might find that's available, and if it is, it's better than GD anyway.
#5

[eluser]Sanity11[/eluser]
To make sure I have also tried ImageMagick. But it doesn't work (because it isn't installed Big Grin ).
But the error messages remain exactly the same. I have double checked with the hosting provider. But it does have all GD2 functionality installed by default. What I find odd is the error message about the path. I am sure it's the right path.
#6

[eluser]TheFuzzy0ne[/eluser]
What's the image name? I would try to keep it alphanumeric with underscores. Things like spaces, and other characters that need escaping could be responsible for the image library claiming the file doesn't exist.
#7

[eluser]Sanity11[/eluser]
Hmmm, the image name is this: test_product_28.jpg. So that's probably fine. Hmmm do you think it makes a difference if I try a overlay instead of text?
#8

[eluser]Sanity11[/eluser]
Ok, I am getting somewhere:

Code:
function do_upload()
    {
        $data = $this->od_model->general();
        
        $config['upload_path'] = './images/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '200';
        $config['max_width']  = '1024';
        $config['max_height']  = '1280';
        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload())
        {
            $upload_info = array('error' => $this->upload->display_errors());
            
            $this->images($upload_info);
        }    
        else
        {    
            $upload_info = array('upload' => $this->upload->data());
            
            $this->od_model->insert_image_data($upload_info['upload']['file_name']);
            
            $this->load->library('image_lib');
        
            $config_wm['source_image'] = './images/uploads/' . $upload_info['upload']['file_name'];
            $config_wm['wm_overlay_path'] = './images/uploads/wm.png';
            $config_wm['wm_type'] = 'overlay';
            $config_wm['wm_vrt_alignment'] = 'bottom';
            $config_wm['wm_hor_alignment'] = 'center';
            $config_wm['wm_padding'] = '20';
            $config_wm['dynamic_output'] = FALSE;
            $config_wm['create_thumb'] = FALSE;
        
            $this->image_lib->initialize($config_wm);
        
            $this->image_lib->watermark();
            
            if (! $this->image_lib->watermark())
            {
                $upload_info = array('wm_info' => $this->image_lib->display_errors(), 'path' => $data['uploaded_images_path'] . $upload_info['upload']['file_name']);
                $this->images($upload_info);
            }
            else
            {
                //Als alles klaar is wordt de functie images aageroepen. Deze herlaadt de pagina zodat de updates zichtbaar zijn.
                $this->images($upload_info);
            }
        }
    }

This works.
Stil a little strange.

Now I have to figure a way to make it upload the original file and a copy with a watermark. Maybe with another name .. _wm at the end or something. So I can easily use it where needed.

Thanks for your help so far by the way Big Grin !
#9

[eluser]Sanity11[/eluser]
Ok, finished. I have just started to work with CI and I must say I love it! For anyone interested:

Code:
function do_upload()
    {
        $data = $this->od_model->general();
        
        $config['upload_path'] = './images/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '200';
        $config['max_width']  = '1024';
        $config['max_height']  = '1280';
        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload())
        {
            $upload_info = array('error' => $this->upload->display_errors());
            
            $this->images($upload_info);
        }    
        else
        {    
            $upload_info = array('upload' => $this->upload->data());
            
            $new_filename = explode('.', $upload_info['upload']['file_name']);
            
            $new_filename_rs = $new_filename[0] . '_rs.' . $new_filename[1];
            $new_filename_wm = $new_filename[0] . '_wm.' . $new_filename[1];
            
            $this->load->library('image_lib');
            
            $config_rs['source_image'] = './images/uploads/' . $upload_info['upload']['file_name'];
            $config_rs['width'] = 500;
            $config_rs['maintain_ratio'] = TRUE;
            $config_rs['new_image'] = './images/uploads/' . $new_filename_rs;
            $config_rs['create_thumb'] = FALSE;
            
            $this->image_lib->initialize($config_rs);
            $this->image_lib->resize();
            
            $config_rs['new_image'] = './images/uploads/' . $new_filename_wm;
            
            $this->image_lib->initialize($config_rs);
            $this->image_lib->resize();
        
            $config_wm['source_image'] = './images/uploads/' . $new_filename_wm;
            $config_wm['wm_overlay_path'] = './images/uploads/wm.png';
            $config_wm['wm_type'] = 'overlay';
            $config_wm['wm_vrt_alignment'] = 'bottom';
            $config_wm['wm_hor_alignment'] = 'center';
            $config_wm['dynamic_output'] = FALSE;
            $config_wm['create_thumb'] = FALSE;
        
            $this->image_lib->initialize($config_wm);
        
            $this->image_lib->watermark();
            
            $this->od_model->insert_image_data($new_filename_rs, $new_filename_wm);
            
            if (! $this->image_lib->watermark())
            {
                $upload_info = array('wm_info' => $this->image_lib->display_errors(), 'path' => $data['uploaded_images_path'] . $upload_info['upload']['file_name']);
                $this->images($upload_info);
            }
            else
            {
                $this->images($upload_info);
            }
        }
    }
#10

[eluser]TheFuzzy0ne[/eluser]
I have to say that although I hardly use the image lib, the configuration is something that's always seemed quite complex for me grasp. Thanks for posting your solution, although I'd still be interested to know what's not right in the original draft.




Theme © iAndrew 2016 - Forum software by © MyBB