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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:36:13+00:00 2026-05-11T21:36:13+00:00

A user will be able to upload an image. If the image is greater

  • 0

A user will be able to upload an image. If the image is greater than a set size I want to downsize it to that size. Obviously it doesn’t have to match exactly due to ratios, the width would be the key size so the height would be variable.

If the image is smaller than the set size I would like to create a new image to the set size with a background of a defined colour and then centre the uploaded image into it therefore the result is the original with paddded colour.

Any code examples or links greatly appreciated

  • 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-11T21:36:13+00:00Added an answer on May 11, 2026 at 9:36 pm

    Here’s a snippet of code I quickly knocked up for resizing it based on the width. I’m sure you could figure out how to add a background color to the Bitmap. It’s not complete code but just an idea of how to do things.

    public static void ResizeLogo(string originalFilename, string resizeFilename)
    {
        Image imgOriginal = Image.FromFile(originalFilename);
    
        //pass in whatever value you want for the width (180)
        Image imgActual = ScaleBySize(imgOriginal, 180);
        imgActual.Save(resizeFilename);
        imgActual.Dispose();
    }
    
    public static Image ScaleBySize(Image imgPhoto, int size)
    {
        int logoSize = size;
    
        float sourceWidth = imgPhoto.Width;
        float sourceHeight = imgPhoto.Height;
        float destHeight = 0;
        float destWidth = 0;
        int sourceX = 0;
        int sourceY = 0;
        int destX = 0;
        int destY = 0;
    
        // Resize Image to have the height = logoSize/2 or width = logoSize.
        // Height is greater than width, set Height = logoSize and resize width accordingly
        if (sourceWidth > (2 * sourceHeight))
        {
            destWidth = logoSize;
            destHeight = (float)(sourceHeight * logoSize / sourceWidth);
        }
        else
        {
            int h = logoSize / 2;
            destHeight = h;
            destWidth = (float)(sourceWidth * h / sourceHeight);
        }
        // Width is greater than height, set Width = logoSize and resize height accordingly
    
        Bitmap bmPhoto = new Bitmap((int)destWidth, (int)destHeight, 
                                    PixelFormat.Format32bppPArgb);
        bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
    
        Graphics grPhoto = Graphics.FromImage(bmPhoto);
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
    
        grPhoto.DrawImage(imgPhoto,
            new Rectangle(destX, destY, (int)destWidth, (int)destHeight),
            new Rectangle(sourceX, sourceY, (int)sourceWidth, (int)sourceHeight),
            GraphicsUnit.Pixel);
    
        grPhoto.Dispose();
    
        return bmPhoto;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try something like this: SetEnvIf Host ^abc\. HOST_ABC SetEnvIf Host… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer I found the answer at the TechNet Forums. <script language="vbscript">… May 12, 2026 at 7:35 am
  • Editorial Team
    Editorial Team added an answer Start with: $lines = explode("\n",$message_data); $headers = array(); $body =… May 12, 2026 at 7:35 am

Related Questions

I have an API consisting of ASP.NET webservices callable through GET/POST/SOAP. A new functionality
I have a couple of solutions, but none of them work perfectly. Platform ASP.NET
Since all files in a web project are compiled into single assembly, then does
I have the need to relatively quickly be able to determine if a set

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.