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

  • Home
  • SEARCH
  • 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 6037079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:01:15+00:00 2026-05-23T06:01:15+00:00

I have an area on a site that I am working on that will

  • 0

I have an area on a site that I am working on that will display a users profile image that is pulled from an external source (therefore no control on its original size).

What I am looking to do is take an image (in this example 1000px x 800px and resize it to 200px x 150px. Obviously with this there is an aspect ratio difference.

What I want to do is resize the original image without distortion, which in this case would produce a 200px x 160px image. What I then want to do is crop any excess from the edges to produce the correct image size. So in this case crop 5px off the top and bottom of the image finally producing a 200px x 150px.

I have the WideImage library currently and would like to use that. I have seen several similar questions on SO but nothing that I can say exactly does as I am trying to achieve.

  • 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-23T06:01:15+00:00Added an answer on May 23, 2026 at 6:01 am

    You might try:

    $img->resize(200, 150, 'outside')->crop('center', 'middle', 200, 150);
    

    Some users post their versions of calculations… Here’s also my version:

    $sourceWidth = 1000;
    $sourceHeight = 250;
    
    $targetWidth = 200;
    $targetHeight = 150;
    
    $sourceRatio = $sourceWidth / $sourceHeight;
    $targetRatio = $targetWidth / $targetHeight;
    
    if ( $sourceRatio < $targetRatio ) {
        $scale = $sourceWidth / $targetWidth;
    } else {
        $scale = $sourceHeight / $targetHeight;
    }
    
    $resizeWidth = (int)($sourceWidth / $scale);
    $resizeHeight = (int)($sourceHeight / $scale);
    
    $cropLeft = (int)(($resizeWidth - $targetWidth) / 2);
    $cropTop = (int)(($resizeHeight - $targetHeight) / 2);
    
    var_dump($resizeWidth, $resizeHeight, $cropLeft, $cropTop);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a site that has tests users can take. I have
I have a site layout I'm working on that has a main content area
I have a image hosting site in CI with an image view file (working
I have an old user site that we are currently updating. The site's users
I have a Tools area of the MVC3 site I'm currently working on. One
I'm working on a Wordpress site that uses the Reason theme from Themeforest. I
I would like to have my site’s logo shown in the icon area of
Working on an MVC3 project. I have an area named Area with an areaRegistration
I have a text area in a form that has a character limit and
I have a text-area where text and an image url is entered. Text is

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.