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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:15:29+00:00 2026-06-04T12:15:29+00:00

I have a problem that I thought was easily solved, but is turning out

  • 0

I have a problem that I thought was easily solved, but is turning out a little more difficult than anticipated.

I am working on a site which someone can upload images for a product, and it resizes them twice (500×500 and 150×150) on the fly. I am trying to keep the aspect ratio, for example if I had 600×500 image it would resize to 500×417 and 150×125.

I have found (lots) of code that does this, such as this class, however I always run into memory issues. I think the class isn’t unloading/destroying the temporary images after resizing.

I had the host upgrade my memory-limit to 64M from 32, however I run out of memory later. I’m stuck with PHP 5.2.13 as well, so no garbage collector for me.

My PHP is fairly new, so it’s very alien to me how classes work, otherwise I would try adding the imagedestroy() function where required. I fiddled with the linked class for hours without success.

Can anyone either:

-Point me in the direction of a magic class that keeps aspect as well as unloading/destroying temporary images after resizing is complete, to keep RAM usage under control?

-Give me some (much needed!) guidance on where and how I could modify a class (such as the one posted) to destroy temporary images.

-Tell me if I’m going around this extremely wrong?

Oh, and I had the WideImage class working at one point, and it worked great, then suddenly stopped. I spent hours trying to fix it with no success.

My PHP install has GD, but not ImageMagick.

Thanks!

  • 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-06-04T12:15:30+00:00Added an answer on June 4, 2026 at 12:15 pm

    Well, I managed to solve my own problem.

    I sat down, wiped all my resize code, and started from scratch, and wrote this wonderful little function to do what I needed.

    function resizeimage($targetw, $targeth, $input, $savedest) {
        list($oldw, $oldh) = getimagesize($input);
        $imgratio = ($oldw / $oldh);
         if ($imgratio>1) { 
             $new_width = $targetw; 
             $new_height = ($targeth / $imgratio); 
         } else { 
             $new_height = $targeth; 
             $new_width = ($targetw* $imgratio); 
         }
      $imagetemp = imagecreatetruecolor($new_width, $new_height);
      $imageorig = imagecreatefromjpeg($input);
      imagecopyresampled($imagetemp, $imageorig, 0, 0, 0, 0, $new_width, $new_height, $oldw, $oldh);
      imagejpeg($imagetemp, $savedest, 95);
      imagedestroy($imageorig);
      imagedestroy($imagetemp);
      unset($oldw,$oldh,$imgratio,$new_height, $new_width, $imagetemp, $imageorig);
    }
    

    Feed in target width and height, as well as the location of the input image (eg “uploads/images/testimage.jpg”), and where you want it saved (“uploads/images/resizedtestimage.jpg”).

    Hope this snippet helps someone in the future!

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

Sidebar

Related Questions

I have a problem that I thought someone may be able to help me
(I have a problem that I illustrated in this question but had no correct
i have a problem that i can't solve ! (sqlite3, but i think it
I have a problem that someone introduced a bug but I do not know
I have a problem of web pages being cached even though I specify that
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that output string must be utf8-formatted, I am writing currently
We have the problem that we have the open project files in our SVN
I have this problem that my sites uses alot of ajax and when a
I have a problem that I have not faced before: It seems that the

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.