Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:50:46+00:00 2026-05-26T07:50:46+00:00

I am working on a project at the moment, where I need to resample

  • 0

I am working on a project at the moment, where I need to resample an uploaded image 3 times, my problem is that if I upload only 1 image, the image only re-samples once, and I am not sure as to where it is only resampling once, below is my code,

if(is_array($this->input->post()) && $this->input->post('uploader_count') != "")
    {
        for($i=0; $i < (int)$this->input->post('uploader_count'); $i++)
        {
            //set up the first image manipulation, this goes from source image to a 209 wide image
            $config['image_library'] = 'gd2';
            $config['source_image'] = './media/uploads/headshots/'.$_POST['uploader_'.$i.'_name'];
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = FALSE;
            $config['new_image'] = './media/uploads/headshots/width_209_'.$_POST['uploader_'.$i.'_name'];
            $config['width'] = 209;

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

            $this->image_lib->clear();
            $this->image_lib->initialize($config);

            if(!$this->image_lib->resize())
            {   
                echo $this->image_lib->display_errors();
            }
            else
            {
                $image = array(
                    'url' => $config['new_image'],
                    'asset_type' => 'image',
                    'asset_size' => 'large',
                    'date_uploaded' => date("Y-m-d h:i:s"),
                    'candidates_candidate_id' => $this->session->userdata('candidates_candidate_id')
                );

                $this->candidates_assets_model->insert($this->security->xss_clean($image));

                //this goes from a 209 image to a 104
                $config2['image_library'] = 'gd2';
                $config2['source_image'] = './media/uploads/headshots/width_209_'.$_POST['uploader_'.$i.'_name'];
                $config2['create_thumb'] = FALSE;
                $config2['maintain_ratio'] = FALSE;
                $config2['new_image'] = './media/uploads/headshots/width_104_'.$_POST['uploader_'.$i.'_name'];
                $config2['width'] = 104;

                $this->image_lib->clear();
                $this->image_lib->initialize($config2);

                if(!$this->image_lib->resize())
                {   
                    echo $this->image_lib->display_errors();
                }
                else
                {
                    $image = array(
                        'url' => $config2['new_image'],
                        'asset_type' => 'image',
                        'asset_size' => 'medium',
                        'date_uploaded' => date("Y-m-d h:i:s"),
                        'candidates_candidate_id' => $this->session->userdata('candidates_candidate_id')
                    );

                    $this->candidates_assets_model->insert($this->security->xss_clean($image));

                    //this goes from a 104 image to 60
                    $config3['image_library'] = 'gd2';
                    $config3['source_image'] = './media/uploads/headshots/width_104_'.$_POST['uploader_'.$i.'_name'];
                    $config3['create_thumb'] = FALSE;
                    $config3['maintain_ratio'] = FALSE;
                    $config3['new_image'] = './media/uploads/headshots/width_60_'.$_POST['uploader_'.$i.'_name'];
                    $config3['width'] = 60;

                    $this->image_lib->clear();
                    $this->image_lib->initialize($config3);

                    if(!$this->image_lib->resize())
                    {   
                        echo $this->image_lib->display_errors();
                    }
                    else
                    {
                        $image = array(
                            'url' => $config3['new_image'],
                            'asset_type' => 'image',
                            'asset_size' => 'small',
                            'date_uploaded' => date("Y-m-d h:i:s"),
                            'candidates_candidate_id' => $this->session->userdata('candidates_candidate_id')
                        );

                        $this->candidates_assets_model->insert($this->security->xss_clean($image));
                    }
                }
            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:50:47+00:00Added an answer on May 26, 2026 at 7:50 am

    Have a go with this code, see if you still have the problem:

    if (is_array($this->input->post()) && $this->input->post('uploader_count') != "") {
    
      // This (probably) only needs to be done once at the beginning
      $this->load->library('image_lib');
    
      $baseImage = array ( // These options are the same for every resample
        'asset_type' => 'image',
        // Set this once at the beginning, so you get the actual upload time, not the time the resample completed
        'date_uploaded' => date("Y-m-d h:i:s"),
        'candidates_candidate_id' => $this->session->userdata('candidates_candidate_id')
      );
    
      for ($i = 0; $i < (int) $this->input->post('uploader_count'); $i++) { // Loop uploaded images
    
        $baseConfig = array ( // These options are the same for every resample
          'image_library' => 'gd2',
          // You can use the original upload as the source for each resample - this will result in better quality
          'source_image' => './media/uploads/headshots/'.$_POST["uploader_{$i}_name"],
          'create_thumb' => FALSE,
          'maintain_ratio' => FALSE
        );
    
        // Since you are doing the same thing over and over, you can tidy it up with a foreach()
        foreach (array (209=>'large', 104=>'medium', 60=>'small') as $width => $sizeName) {
    
          // Fetch the base config and set options for this iteration
          $config = $baseConfig;
          $config['new_image'] = "./media/uploads/headshots/width_{$width}_".$_POST["uploader_{$i}_name"];
          $config['width'] = $width;
    
          // Set up the image manipulation
          $this->image_lib->clear();
          $this->image_lib->initialize($config);
    
          if (!$this->image_lib->resize()) { // If resize fails, move onto next uploaded image
            echo $this->image_lib->display_errors();
            continue 2;
          }
    
          // Fetch the base image and set options for this iteration
          $image = $baseImage;
          $image['url'] = $config['new_image'];
          $image['asset_size'] = $sizeName;
    
          // Do the insert for this image data
          $this->candidates_assets_model->insert($this->security->xss_clean($image));
    
        } // End foreach
    
      } // End for
    
    } // End if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project at the moment that requires a dialog box
The project that I am currently working on at the moment uses SVN for
I'm working on a project at the moment where I need to pick out
I have begun working on a project that, at the moment, produces a monolithic
I am working on a project where at a certain moment I need to
Basically my problem is a that I need to copy an uploaded file (which
This is a toy project I'm working on at the moment. My app contains
I working on project and have problem with threading and update of UI. I
I'm working on project that lets users choose some scientific authors and columnists and
I am working a project with many NUnit tests, that were already written long

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.