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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:40:33+00:00 2026-05-16T10:40:33+00:00

I have a website going that takes a user’s uploaded image, and makes three

  • 0

I have a website going that takes a user’s uploaded image, and makes three copies – a ‘full’ copy to print with (downsized to 1500×1125), a ‘web’ copy to display online (not coded yet), and finally a thumbnail.

So here’s the code – _imageformat() is passed the parameters (which I’ve confirmed to be correct) from CI’s Upload Class:

function _imageformat($fullpath, $shortpath, $width, $height)

{
// We now format the image.

// First, we check if it is landscape or portrait
if ($width >= $height) // It’s landscape (or square)
{
// Now create the full printing image
$fullimage = $this->_resize(‘l’, $fullpath, $shortpath, $width, $height);
}
else // It’s portrait
{
// Now create the full printing image
$fullimage = $this->_resize(‘p’, $fullpath, $shortpath, $width, $height);
}

}

function _resize($type, $fullpath, $shortpath, $width, $height)
{
// Set up the default Image Manipulation config options
$config[‘image_library’] = ‘gd2’;
$config[‘source_image’] = $fullpath;
$config[‘maintain_ratio’] = TRUE;

// Shave the '.jpg' from the end to append some nice suffixes we'll use
$newimage = substr($fullpath, 0, -4).'_full'.".jpg";

$config['new_image'] = $newimage;

if ($type == 'l') // If it's landscape
{
 $config['width'] = 1500;
 $config['height'] = 1125;
}
else if ($type == 'p') // If it's portrait
{
 $config['width'] = 1125;
 $config['height'] = 1500;   
}

// Load the image library with the specified parameters, and resize the image!  
$this->load->library('image_lib', $config); 
$this->image_lib->resize();

// Create a thumbnail from the full image
$config['source_image']  = $newimage;
$config['new_image']  = substr($fullpath, 0, -9)."_thumb".".jpg";
$config['maintain_ratio']  = TRUE;
$config['width']    = 150;
$config['height']   = 150;

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

$this->image_lib->resize();

return $newimage;

}

What SHOULD happen: In my uploads folder, there are three images – the original uploaded file (we’ll call it image.jpg), the resized file (named image_full.jpg), and the thumbnail (named image_thumb.jpg).

What DOES happen: In my uploads folder, there are only TWO images – the original uploaded file (image.jpg), and the resized file (image_full.jpg). No thumbnail is ever created.

What’s interesting, however, ** is that if I place the code for the Thumbnail creation first, it generates the thumbnail image but **NOT the _full (resized) image.

So it appears to me that it won’t ever run $this->image_lib->resize() twice. Why not? Is it some amateur mistake I’m making, or have I missed something obvious?! 😛

Thanks!

Jack

Edit: I should point out that yes, I know I’m loading the image_lib library twice. I fathomed this was the only way of passing new parameters to it. I also tried, after resizing the full image, calling $this->_thumbnail() which loaded the library again there. But still the same issue occurred.

Edit 2: I’ve also tried using $this->image_lib->clear() – still no luck.

  • 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-16T10:40:34+00:00Added an answer on May 16, 2026 at 10:40 am

    You should load the library only once and initialize it with different configs:

    $this->load->library('image_lib');
    
    // full image stuff
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    
    // thumbnail stuff
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.