简体   繁体   English

插入前调整图像大小-GROCERY CRUD / CODE IGNITER

[英]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. 我正在尝试调整通过Grocery Crud上传的图像的大小,但是遇到了一些困难,因为我不确定如何访问POST数组中的内容,因此可以在代码中使用它。

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. 我确定这与填充$file_uploaded变量有关,但是我不知道如何查看Grocery CRUD发布的内容以查看应使用的内容。 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. 我确实已打开CI分析器,但是我认为Grocery CRUD会在处理上传内容之前对其进行重定向,然后才有机会查看发布的内容。

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 http://ellislab.com/codeigniter/user-guide/libraries/image_lib.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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