Coder Social home page Coder Social logo

Comments (8)

christoffwalker avatar christoffwalker commented on August 19, 2024

Update:

I ran a foreach after the $this->upload->get_multi_upload_data(); and before return $image_data; and specified the images sizes in there and seems to be working well:

foreach($image_data as $k => $v) {
    $config = array(
        'source_image' => $v['full_path'],
        'maintain_ratio' => TRUE,
        'width' => 1400,
        'height' => 800
    );
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
}

Hope this helps anyone else...

from codeigniter-multi-upload.

christoffwalker avatar christoffwalker commented on August 19, 2024

This is doesn't quite work... (Darn!)

It does for a single upload, but upload more than one image seems to break it.
Any ideas would be much appreciated...

from codeigniter-multi-upload.

stvnthomas avatar stvnthomas commented on August 19, 2024

Is there an actual error? Here's a snippet of what I use in one of my models for reference. This loads the image_lib library once outside the loop and the settings are being cleared after each resize.

if($this->upload->do_multi_upload("files")){
    $data = $this->upload->get_multi_upload_data();

    $this->load->library("image_lib");
    foreach($data as $file){
        if((int)$file["is_image"] === 1){
            $this->image_lib->initialize(array(
                "width"         => 1280,
                "height"        => 1024,
                "master_dim"    => "width",
                "source_image"  => $file["full_path"]
            ));
            $this->image_lib->resize();
            $this->image_lib->clear();
        }
    }
}

from codeigniter-multi-upload.

christoffwalker avatar christoffwalker commented on August 19, 2024

Hi Steven,

Not getting an error as such, but when I tried multiple images, whilst they still uploaded the first didn't resize and the subsequent image was resized to top-left, with the rest of the image as a black background.

But thanks very much or your snippet, this looks much better, I'll give that a whirl...

from codeigniter-multi-upload.

christoffwalker avatar christoffwalker commented on August 19, 2024

Your code works a treat, thanks again.
I reckon not having $this->image_lib->clear(); was partly to blame.
Cheers!

from codeigniter-multi-upload.

christoffwalker avatar christoffwalker commented on August 19, 2024

Any thoughts on why it's uploading both original and resized?
Ideally just need to resize...

from codeigniter-multi-upload.

christoffwalker avatar christoffwalker commented on August 19, 2024

Here's my full model code:

function do_multi_upload($property_id) {
    $this->load->library('upload');
    // Filenames array
    $filenames_ar = array();
    $i = 0;
    foreach($_FILES['files']['name'] as $k => $v) {
        $rand               = mt_rand(100000,999999);
        $segments           = explode('.', $v);
        $extension          = strtolower(array_pop($segments));
        $name               = "img_{$property_id}_{$rand}.{$extension}";
        $filenames_ar[$k]   = "{$name}";
        $i++;
    }
    $this->upload->initialize(array(
        "upload_path"   => FCPATH.'static/images/uploaded/',
        "file_name"     => $filenames_ar,
        "allowed_types" => 'jpg',
        "max_size"      => '0',
    ));
    
    // stvnthomas
    if(!$this->upload->do_multi_upload("files")) {
        
        $error = array('error' => $this->upload->display_errors());
        return $error;
        
    } else {
        
        if($this->upload->do_multi_upload('files')){
            $image_data = $this->upload->get_multi_upload_data();
            $this->load->library('image_lib');
            foreach($image_data as $file){
                if((int)$file["is_image"] === 1) {
                    $this->image_lib->initialize(array(
                        'source_image'   => $file['full_path'],
                        'maintain_ratio' => TRUE,
                        'width'          => 1400,
                        'height'         => 800,
                        'master_dim'     => 'auto'
                        ));
                    $this->image_lib->resize();
                    $this->image_lib->clear();
                }
            }
        }
        return $image_data;
    }
}

from codeigniter-multi-upload.

stvnthomas avatar stvnthomas commented on August 19, 2024

Sorry for the late reply. I don't initially see anything wrong with your snippet. Hopefully you got it sorted out. This post seems to imply calling clear() before initialize() might fix the problem: https://ellislab.com/forums/viewthread/173145/#865917.

from codeigniter-multi-upload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.