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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:50:25+00:00 2026-05-22T01:50:25+00:00

I’m working on an image upload script with PHP, I found one someone was

  • 0

I’m working on an image upload script with PHP, I found one someone was offering and tried modifying it, however, i’m running into a few problems.

I want to do the following:
Detect the longest side of the image (ie. portrait or landscape)
And then resize the image, with the longest side being 800px AND keep proportions.

Here is the code I have so far.. For landscape images it works fine, but with portrait ones it distorts them like crazy.
PS. I’m making a larger image as well as a thumbnail.

list($width,$height)=getimagesize($uploadedfile);

if($width > $height){

    $newwidth=800;
    $newheight=($height/$width)*$newwidth;

    $newwidth1=150;
    $newheight1=($height/$width)*$newwidth1;

} else {


    $newheight=800;
    $newwidth=($height/$width)*$newheight;


    $newheight1=150;
    $newwidth1=($height/$width)*$newheight;

}
$tmp=imagecreatetruecolor($newwidth,$newheight);
$tmp1=imagecreatetruecolor($newwidth1,$newheight1);
  • 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-22T01:50:26+00:00Added an answer on May 22, 2026 at 1:50 am

    You’re probably mistaking:

    When $width > $height that means it’s landscape. Setting maxwidth to 800 means (height/width)*800 = new height. On the other hand $height > $width means setting maxheight to 800 and thus having (width/height)*800 is new width.

    Right now your using both the height/width ratio instead of the other way around. Example:

    Image: 1600 (w) x 1200 (h)
    Type: Landscape
    New Width: 800
    New Height: (1200 (h) / 1600(w) * 800 (nw) = 600
    
    Image 1200 (w) x 1600 (h)
    Type: Portrait
    New Height: 800
    New Width: (1200 (w) / 1600(h) * 800 (nh) = 600
    

    Hope you get what I’m saying, you just switched them 🙂 Also notice that you multiply with $newheight instead of $newheight1 for the portrait thumbnail

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.