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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:43:01+00:00 2026-05-19T01:43:01+00:00

This is a followup question to PHP: if more than ..px resize to As

  • 0

This is a followup question to PHP: if more than ..px resize to

As you can see it resizes if:

if($width > 604 && $height > 453) {

This works fine is both the width and height are large.

However, if $width is over 604, and $height is under 453 (e.g. 604×300)m then this will skip the resize procedure. The opposite is the same(width is under, height is over). Also, if the dimensions on a picture is 500×900, and it gets resized, it gets really ugly resized. any great fix?

Any good suggestion on how I should handle this please?

edit:

$rel_difference = array('width'=>0, 'height'=>0);

if($width > 604 || $height > 453) {
    if($width > 604) $rel_difference['width'] = ($width-604)/604;
    if($height > 453) $rel_difference['height'] = ($height-453)/453;

asort($rel_difference);

$newwidth = $width/(1+end($rel_difference));
$newheight = $height/(1+end($rel_difference)); 
$newwidth = round($newwidth);
$newheight = round($newheight);
$jpeg_quality = 90;
$src = "images/users/status/".$org_name;
$path_thumbs = "images/users/status/"; 
$thumb_path = $path_thumbs . '/' . $newfilename;

switch(exif_imagetype($move_me)) {
    case IMAGETYPE_GIF:
        $img_r = imagecreatefromgif($src);
    break;
    case IMAGETYPE_JPEG:
        $img_r = imagecreatefromjpeg($src);
    break;
    case IMAGETYPE_PNG:
        $img_r = imagecreatefrompng($src);
    break;
    default:
            echo "{";
            echo        "error: 'Not a image!'";
            echo "}";
        exit(0);
    break;
}
$dst_r = ImageCreateTrueColor( $newwidth, $newheight );

imagecopyresampled($dst_r, $img_r, 0, 0, 0, 0, $newwidth , $newheight, $width, $height);

imagejpeg($dst_r,$thumb_path,$jpeg_quality);

unlink($move_me);
    }
  • 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-19T01:43:02+00:00Added an answer on May 19, 2026 at 1:43 am

    You can do somthing like:

    $width = 1000;
    $height = 900;
    
    $rel_difference = array('width'=>0, 'height'=>0);
    if($width > 604 || $height > 453) {
        if($width > 604) $rel_difference['width'] = ($width-604)/604;
        if($height > 453) $rel_difference['height'] = ($height-453)/453;
    }
    
    asort($rel_difference);
    
    print_r($rel_difference);
    

    Which would output something like:

    Array ( width] => 0.65562913907285 [height] => 0.98675496688742 )
    

    Now you know the largest difference to max.

    Which will be:

    end($rel_difference);
    

    So you can scale using this value proportional.

    EDIT

    removed unnecessary array_reverse

    EDIT2

    // now lets calculate the new dimensions based on our previous code
    // I divide the dimensions with the largest difference + 1 to get to the new dimensions
    
    $newwidth = $width/(1+end($rel_difference)); // 503.33333333333
    $newheight = $height/(1+end($rel_difference)); // 453
    

    The image is now proportionally scaled.

    Don’t know whether you can use that much decimals places if not use some rounding.

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

Sidebar

Related Questions

this is a followup to my previous question , whereby I'm writing a PHP
This is a followup question to my other widget-related question . I'd like to
This is a followup question to my other question : Run bat file in
This is a followup on the question: ASP.NET next/previous buttons to display single row
This is a followup to a question I posted yesterday. I thought everything was
As a followup to this question , is it possible to write a single
NOTE: This is a followup to my question here. I have a program that
This is a followup of a previous question I had. I got the very
This is a followup to an earlier question ( Help Refining RegEx ("\b\d{6}([ ]{1,15})\d{7}\b")
This is a followup to my last question . I now have a byte[]

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.