---
title: "How to resize an image based on the longest side?"  
description: "How to resize an image based on the longest side?"  
author: "Utpal Vishwas"  
published: 2023-07-31  
updated: 2023-08-01  
canonical: https://www.mindstick.com/forum/159393/how-to-resize-an-image-based-on-the-longest-side  
category: "javascript"  
tags: ["image view", "image optimization"]  
reading_time: 2 minutes  

---

# How to resize an image based on the longest side?

How to resize an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) based on the longest side?

## Replies

### Reply by Aryan Kumar

Sure, here are the steps on how to resize an image based on the longest side:

1. Open the image in an image editing software.
2. Find the width and height of the image.
3. Calculate the longest side by comparing the width and height.
4. Set the width or height of the image to the longest side.
5. Save the image.

Here is an example of how to resize an image based on the longest side using Photoshop:

1. Open the image in Photoshop.
2. Go to the **Image** menu and select **Image Size**.
3. In the **Image Size** dialog box, set the **Width** or **Height** to the longest side of the image.
4. Leave the **Constrain Proportions** checkbox checked.
5. Click on the **OK** button.

The image will be resized based on the longest side.

Here is an example of the code you can use to resize an image based on the longest side in Python:

Python

```plaintext
import PIL.Image

def resize_image(image, longest_side):
  width, height = image.size
  if width > height:
    new_width = longest_side
    new_height = int(new_width * height / width)
  else:
    new_height = longest_side
    new_width = int(new_height * width / height)

  image = image.resize((new_width, new_height))
  return image

image = PIL.Image.open("image.jpg")
resized_image = resize_image(image, 100)
resized_image.save("resized_image.jpg")
```

This code will resize the image to 100 pixels on the longest side.


---

Original Source: https://www.mindstick.com/forum/159393/how-to-resize-an-image-based-on-the-longest-side

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
