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 669757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:11:09+00:00 2026-05-14T00:11:09+00:00

I’m using Codeigniter’s image manipulation library to re-size an uploaded image to three sizes,

  • 0

I’m using Codeigniter’s image manipulation library to re-size an uploaded image to three sizes, small, normal and large.

The re-sizing is working great. However, if I’m resizing a vertical image, the library is rotating the image so it’s horizontal.

These are the config settings I have in place:

     $this->resize_config['image_library'] = 'gd2';
     $this->resize_config['source_image'] = $this->file_data['full_path'];
     $this->resize_config['maintain_ratio'] = TRUE;

     // These change based on the type (small, normal, large)
     $this->resize_config['new_image'] = './uploads/large/'.$this->new_file_name.'.jpg';
     $this->resize_config['width'] = 432;
     $this->resize_config['height'] = 288;

I’m not setting the master_dim property because the default it set to auto, which is what I want.

My assumption is that the library would take a vertical image, see that the height is greater than the width and translate the height/width config appropriately so the image remains vertical.

What is happening (apparently) is that the library is rotating the image when it is vertical and sizing it per the configuration.

This is the code in place I have to do the actual re-sizing:

        log_message('debug', 'attempting '.$size.' photo resize');
        $this->CI->load->library('image_lib');
        $this->CI->image_lib->initialize($this->resize_config);
        if ($this->CI->image_lib->resize())
        {
              $return_value = TRUE;
              log_message('debug', $size.' photo resize successful');
        }
        else
        {
            $this->errors[] = $this->CI->image_lib->display_errors();
            log_message('debug', $size.' photo resize failed');
        }
        $this->CI->image_lib->clear();
        return $return_value;

EDIT

I think the problem may be from the upload library. When I get the image_height and image_width back from the upload, the width seems to be larger even though I uploaded a vertical image.

This is a portion of the code I’m using to upload the photo:

     $this->upload_config['allowed_types'] = 'jpg|jpeg';
     $this->upload_config['max_size']  = '2000';
     $this->upload_config['max_width']  = '0';
     $this->upload_config['max_height']  = '0';
     $this->upload_config['upload_path'] = './uploads/working/';


     $this->CI->load->library('upload', $this->upload_config);
     if ($this->CI->upload->do_upload($this->posted_file))
     {
         $this->file_data = $this->CI->upload->data();
         $return_value = TRUE;
         log_message('debug', 'upload successful');
     }

I added some logging to check the values:

     $this->is_vertical = $this->file_data['image_height'] > $this->file_data['image_width'];
     log_message('debug', 'image height:'.$this->file_data['image_height']);
     log_message('debug', 'image width:'.$this->file_data['image_width']);
     if ($this->is_vertical)
     {
         $this->resize_config['master_dim'] = 'height';
     }
     else
     {
         $this->resize_config['master_dim'] = 'width';
     }
    log_message('debug', 'master_dim setting:'.$this->resize_config['master_dim']); 

These are the results of the log:

DEBUG – 2010-03-16 18:35:06 –> image height:1536
DEBUG – 2010-03-16 18:35:06 –> image width:2048
DEBUG – 2010-03-16 18:35:06 –> master_dim setting:width

Looking at the image in photoshop, these are the dimensions:

height: 2048
width: 1536

Anyone know what might be causing the upload library to do this?

  • 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-14T00:11:09+00:00Added an answer on May 14, 2026 at 12:11 am

    Ok – I decided not to trust photoshop and opened the images I was testing in quicktime and safari. I discovered that they were actually still horizontal.

    So Codeigniter was operating exactly as expected.

    I went back into photoshop, did a save for web on the test images, re-uploaded them and it worked as expected.

    I then stripped out the extra code that I had added to test whether the image was vertical and the library works as I expected it would.

    Now – I need to figure out how to prevent end users from doing this exact thing.

    Thanks for taking the time to answer my question musoNic80. Hopefully someone else can learn from my mistakes here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 391k
  • Answers 391k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Change one of the literals into a decimal: decimal avg… May 15, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer That would be best performed with a join: select B.*… May 15, 2026 at 1:18 am
  • Editorial Team
    Editorial Team added an answer Looks ok to me. Have you tried the simpler syntax… May 15, 2026 at 1:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.