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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:16:26+00:00 2026-05-26T07:16:26+00:00

How can I crop an image automatically through the upload process? Is there php

  • 0

How can I crop an image automatically through the upload process? Is there php function to do that?

I want my webpage to display the images with the same dimension from various dimension of the original images by cropping it.

Or any idea?

  • 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-26T07:16:26+00:00Added an answer on May 26, 2026 at 7:16 am

    Say this as max_size.php

    <?php header('Content-type: image/jpeg');
    function resampleimage($maxsize, $sourcefile, $imgcomp=0){
    $g_imgcomp=100-$imgcomp;
        if(file_exists($sourcefile)){
        $g_is=getimagesize($sourcefile);
            if($g_is[0] <= $maxsize && $g_is[1] <= $maxsize){
                $new_width=$g_is[0];
                $new_height=$g_is[1];
            } else {
                $w_adjust = ($maxsize / $g_is[0]);
                $h_adjust = ($maxsize / $g_is[1]);
          if($w_adjust <= $h_adjust){
              $new_width=($g_is[0]*$w_adjust);
              $new_height=($g_is[1]*$w_adjust);
          } else {
              $new_width=($g_is[0]*$h_adjust);
              $new_height=($g_is[1]*$h_adjust);
          }
        }
        $image_type = strtolower(strrchr($sourcefile, "."));
    
        switch($image_type) {
          case '.jpg':
             $img_src = imagecreatefromjpeg($sourcefile);
             break;
          case '.jpeg':
             $img_src = imagecreatefromjpeg($sourcefile);
             break;
          case '.png':
             $img_src = imagecreatefrompng($sourcefile);
             break;
          case '.gif':
             $img_src = imagecreatefromgif($sourcefile);
             break;
          default:
             echo("Error Invalid Image Type");
             die;
             break;
       }
      $img_dst=imagecreatetruecolor($new_width,$new_height);
      imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $g_is[0], $g_is[1]);
      imagejpeg($img_dst);
      imagedestroy($img_dst);
      return true;
      } else {
      return false;
      }
    }
    resampleimage($_GET['maxsize'], $_GET['source']);
    ?>
    

    In the page where you have image

    <img id="img" src="max_size.php?maxsize=152&source=[some image path]" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can we upload and crop the image using PHP.
how can i crop the image with php with its exact to the face
Im looking for upload and crop image in PHP. The scenario is: user choose
I have created a image crop facility that I can click on an image
i want to crop image via drawing circle using touchMoved event. so how can
I want to build an upload applet / desktop client that can resize -
I have this upload then you can crop your image, but if you press
I want to crop an image using images library of google app engine. The
I want to upload and crop an image via ajax. Please suggest how I
I have noticed that every image I upload to Facebook is cropped automatically for

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.