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

  • Home
  • SEARCH
  • 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 3457946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:55:21+00:00 2026-05-18T09:55:21+00:00

I have spent days trying to make this work based on the examples in

  • 0

I have spent days trying to make this work based on the examples in the documentation but I am missing something or I am just STUPID!

I have a CMS application where users upload an image for display in a very fixed layout. We do not want to limit the file size of the uploaded image but would rather “process” it after it arrives.

The image needs to be 615px wide but some of the images uploaded directly from digital cameras are 2500X2000 and bigger so this is CRITICAL.

I pieced together the code from the manual and the image is successfully being uploaded to a folder within the CMS app. However, the image is NOT being resized.

If I ever get it to re-size, my plan is to present the image to the user for cropping using jCrop (the final image HAS to be 615X275 and it probably has to be cropped for height after resizing) and then use codeigniter to FTP the image to their site’s amenities folder using the original name.

I will appreciate any help in this matter!

Here’s my code:

function do_feature_upload() {
        $imageName = $this->uri->segment(3);
        //echo $imageName;

        // Where the file is going to be placed
        $config['upload_path'] =  "./uploads/".$_SESSION['dbPropNumber'];
        $config['allowed_types'] = 'jpg|jpeg';
        $config['max_size'] = '0';
        $config['file_name'] = $imageName.'.jpg';
        $config['overwrite'] = 'TRUE';

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

        if ( ! $this->upload->do_upload()) {
            $error = array('error' => $this->upload->display_errors());

            $error['propertyDropdown'] = $_SESSION['propertyDropdown'];
            $error['username'] = $_SESSION['username'];
            $error['dbPropNumber'] = $_SESSION['dbPropNumber'];
            $error['propertyName'] = $this->content->getPropertyName($_SESSION['dbPropNumber']);

            $this->load->view('upload_AmenityImage', $error);
        } else {
            $image_data = $this->upload->data();

            $origWidth = $image_data['image_width'];
            $origHeight = $image_data['image_height'];
            $newWidth = 615;
            $newHeight = $newWidth*$origHeight/$origWidth;

            $resize = array(
                'image_library'=>'gd2',
                'source_image'=>base_url().'uploads/'.$_SESSION['dbPropNumber'].'/'.$imageName.'.jpg',
                'new_image'=>base_url().'uploads/'.$_SESSION['dbPropNumber'].'/'.$imageName.'1.jpg',
                'create_thumb' => FALSE,
                'maintain_ratio'=>FALSE,
                'width'=>$newWidth,
                'height'=>$newHeight
            );

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

            $data = array('upload_data' => $this->upload->data());
            $data['propertyDropdown'] = $_SESSION['propertyDropdown'];
            $data['username'] = $_SESSION['username'];
            $data['dbPropNumber'] = $_SESSION['dbPropNumber'];
            $data['propertyName'] = $this->content->getPropertyName($_SESSION['dbPropNumber']);

            //Present jCrop option after image is resized

            // FTP to final destination

            $this->load->view('upload_success', $data);
        } // end if
    } // end function
  • 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-18T09:55:21+00:00Added an answer on May 18, 2026 at 9:55 am

    I’m not entirely sure what’s going wrong with your code, but here’s a model function I wrote for resizing images to fit an exact target height and target width. Read through it and see if you can’t figure out the solution.

    $this->prefix is a property in my class that I use so I don’t have to keep writing out the directory of the file. It looks like this:

    $this->prefix = FCPATH.'uploads'.DIRECTORY_SEPARATOR;

    Image resizer

    /**
     * Resizes an image to fit exact dimensions
     * 
     * @param string    filename
     * @param int      target_width
     * @param int      target_height
     * 
     * @return array('success' ? null : 'error')
     */
    function resizeImageToDimensions($filename, $target_width=700, $target_height=399)
    {
        $file_type = $this->getFileType($this->prefix.$filename);
    
        if (!$file_type || $file_type != 'image')
            return array('success'=>false, 'error'=>"This file doesn't exist or isn't an image");
    
        $this->load->library('image_lib');
    
        list($width, $height) = getimagesize($this->prefix.$filename);
        $current_ratio = $width/$height;
        $target_ratio = $target_width/$target_height;
        $config['source_image'] = $this->prefix.$filename;
    
        if ($current_ratio > $target_ratio)
        {
            //resize first to height, maintain ratio
            $config['height'] = $target_height;
            $config['width'] = $target_height * $current_ratio;
            $this->image_lib->initialize($config);
    
            if (!$this->image_lib->resize())
                return array('success'=>false, 'error'=>"There was an error while resizing this image");
    
            //then crop off width
            $config['width'] = $target_width;
            $config['maintain_ratio'] = false;
            $this->image_lib->initialize($config);
    
            if ($this->image_lib->crop())
                return array('success'=>true);
            else
                return array('success'=>false, 'error'=>"There was an error while cropping this image");
        }
        else if ($current_ratio < $target_ratio)
        {
            //resize first to width, maintain ratio
            $config['width'] = $target_width;
            $config['height'] = $target_width / $current_ratio;
            $this->image_lib->initialize($config);
    
            if (!$this->image_lib->resize())
                return array('success'=>false, 'error'=>"There was an error while resizing this image");
    
            //then crop off height
            $config['height'] = $target_height;
            $config['maintain_ratio'] = false;
            $this->image_lib->initialize($config);
    
            if ($this->image_lib->crop())
                return array('success'=>true);
            else
                return array('success'=>false, 'error'=>"There was an error while cropping this image");
        }
        else {
            $config['width'] = $target_width;
            $config['height'] = $target_height;
            $this->image_lib->initialize($config);
    
            if ($this->image_lib->resize())
                return array('success'=>true);
            else
                return array('success'=>false, 'error'=>"There was an error while resizing this image");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I've spent a couple hours trying to resolve this issue and have
I have spent several hours trying to find a means of writing a cross
I have spent too much time on this problem and am beginning to think
I've spent a couple of days trying to find out what's going on. I
This case is really strange, i've spent 2 whole days to get Twitter Oauth
I have spent a lot of time looking for a solution, but could not
I have spent lot of time doing research on VIM. I am Windows guy
A colleague and I have spent a few years developing a really cool Matlab
Have just started using Google Chrome , and noticed in parts of our site,
I have searched for two weeks, every night, exhaustively reading forum threads and trying

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.