简体   繁体   中英

Resize image before insert - GROCERY CRUD/CODE IGNITER

I'm attempting to resize my images on upload through Grocery Crud, but having some difficulty as I'm not sure how to access what is in the POST array so I can use it in my code.

Here is the section of my controller that does the image uploading (specifically the bit where I do the callback:

//Set up a call back function after the file has been uploaded to resize the image to save bandwidth/load times when displayed on the site
        $crud->callback_before_insert(array($this, 'resize_image'));

And here is the function that I'm calling:

private function resize_image ($post_array) 
    {
        $file_uploaded = $post_array (['image_url']);

        $config = array (
        'image_library' => 'gd2',
        'source_image'  => $file_uploaded,
        'create_thumb' => FALSE,
        'maintain_ratio' => TRUE,
        'width'  => 400,
        'height' => 300);

        $this->load->library('image_lib', $config);

        $this->image_lib->resize();

    }

The upload still works fine (ie no errors) but the image remains at its original size. I'm sure it's something to do with what I'm populating the $file_uploaded variable with, but I don't know how to see what is being posted by Grocery CRUD to see what I should be using. I do have the CI profiler turned on, but I think Grocery CRUD redirects on it's processing of an uploaded before you get chance to see what's posted.

Can anyone help??

You have to resize the image after successful upload. Check the below link for more details.

http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM