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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:42:14+00:00 2026-05-19T16:42:14+00:00

I upload the image to my site. Image has width is 498 and height

  • 0

I upload the image to my site. Image has width is 498 and height is 402.
I need to make a preview image with the established maximum width of 250px and a maximum height of 250px, but the image should be 250 to 250, and must be proportional to the width of 250 pixels.

How to do it?

EDIT

I upload images to your server. The limit on the size I want to make 250 in width and 250 in height.
This does not mean that if I upload an image 1000h500, then it must do 250×250, which means that the width we’re doing 250 pixels and the height is proportional to the first dimension is 125. In the end, I should get a picture 250×125.
Second example: I have an image 100h800. I mean it should be changed

  • 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-19T16:42:15+00:00Added an answer on May 19, 2026 at 4:42 pm
    function makeThumbnail($image, $dest)
        {
            $imageType = exif_imagetype($image);
    
            switch ($imageType)
            {
                case IMAGETYPE_JPEG:
                    $img = imagecreatefromjpeg($image);
                    break;
                case IMAGETYPE_PNG:
                    $img = imagecreatefrompng($image);
                    break;
                case IMAGETYPE_GIF:
                    $img = imagecreatefromgif($image);
                    break;
                default:
                    throw new Im_Exception('Bad extension');
            }
    
            $width  = imagesx($img);
            $height = imagesy($img);        
    
            if ($height > $width) 
            {   
                $ratio = 250 / $height;  
                $newHeight = 250;
                $newWidth = $width * $ratio; 
            }
            else
            {
                $ratio = 250 / $width;   
                $newWidth = 250;  
                $newHeight = $height * $ratio;   
            }
    
            $previewImg = imagecreatetruecolor($newWidth, $newHeight); 
    
            $palsize = ImageColorsTotal($img); 
            for ($i = 0; $i < $palsize; $i++) 
            { 
                $colors = ImageColorsForIndex($img, $i);   
                ImageColorAllocate($previewImg, $colors['red'], $colors['green'], $colors['blue']);
            } 
    
            imagecopyresized($previewImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    
            switch ($imageType)
            {
                case IMAGETYPE_JPEG:
                    $ext = 'jpg';
                    imagejpeg($previewImg, $dest . '.' . $ext);
                    break;
                case IMAGETYPE_PNG:
                case IMAGETYPE_GIF:
                    $ext = 'png';
                    imagesavealpha($previewImg, true);
                    imagepng($previewImg, $dest . '.' . $ext, 9);
                    break;
                default:
                    throw new Im_Exception();
            }
            imagedestroy($previewImg);
            imagedestroy($img);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this question I succeeded to create upload image, but now I need
I'm hosting a web site at localhost and need to upload image file to
I'm trying to upload an image to my site through a form, however it's
I need to upload an image as part of a create action in an
I have been creating an image uploading site for a while now but have
I'm using paperclip to upload images to the site but when I do, it
Can you directly upload an image from a URL or from a site using
I have a site where I can upload an image, and i am using
I upload image files using aspupload component. I was wondering if its possible to
How to upload image URL in SQL server and retrieve in grid view using

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.