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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:37:50+00:00 2026-05-24T21:37:50+00:00

Anyone know a good PHP tutorial on how to upload an image, resize it

  • 0

Anyone know a good PHP tutorial on how to upload an image, resize it to set dimension, then store the image path in MySQL?

  • 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-24T21:37:51+00:00Added an answer on May 24, 2026 at 9:37 pm

    I use this function to do this, Very simple and easy to use.
    First put this function somewhere you can call it.

    public function Resize_image($width = 0, $height = 0, $quality = 90, $filename_in = null, $filename_out = null)
    {
        $this->Filename = $filename_in;
        $this->Extension = strtolower($this->Get_file_extension($this->Filename));
    
        $size = getimagesize($this->Filename);
        $ratio = $size[0] / $size[1];
        if ($ratio >= 1){
            $scale = $width / $size[0];
        } else {
            $scale = $height / $size[1];
        }
        // make sure its not smaller to begin with!
        if ($width >= $size[0] && $height >= $size[1]){
            $scale = 1;
        }
    
        // echo $fileext;
        switch ($this->Extension)
        {
            case "jpg":
                $im_in = imagecreatefromjpeg($this->Filename);
                $im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
                imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]);
                imagejpeg($im_out, $filename_out, $quality);
            break;
            case "gif":
                $im_in = imagecreatefromgif($this->Filename);
                $im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
                imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]);
                imagegif($im_out, $filename_out, $quality);
            break;
            case "png":
                $im_in = imagecreatefrompng($this->Filename);
                $im_out = imagecreatetruecolor($size[0] * $scale, $size[1] * $scale);
                imagealphablending($im_in, true); // setting alpha blending on
                imagesavealpha($im_in, true); // save alphablending setting (important)
                imagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $size[0] * $scale, $size[1] * $scale, $size[0], $size[1]);
                imagepng($im_out, $filename_out, 9);
            break;
        }
        imagedestroy($im_out);
        imagedestroy($im_in);
    }
    

    Now you can use this function like so to resize images and copy it to the required directory.

    Resize_image($width, $height, $quality=90, $filename_in, $filename_out)
    Example..
    Resize_image(150, 150, 90, "Directory".$image, "Directory".$image_without_extension."_thumb.".$image_ext); //makes file_thumb.ext
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know any good tutorial on how to upload a file with php
Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license
Anyone know a PHP scripts that done a good compression for jQuery?
Does anyone know of a good tool for cleaning up/formatting PHP files? I'd need
as the title says: Anyone know about any good/simple multiple file upload script that
Does anyone know good example of using CSS to create rounded corner box where:
Anyone know a good book or post about how to start in EF? I
Anyone know a good Regex expression to drop in the ValidationExpression to be sure
Anyone know a good lib where i can run the strings before they are
Anyone know a good solution for filtering input using jQuery? I'd like to do

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.