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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:11:08+00:00 2026-05-18T09:11:08+00:00

Oddly enough, I can’t find any info on this topic: user profile pictures. Is

  • 0

Oddly enough, I can’t find any info on this topic: user profile pictures.

Is there a PHP solution for the following?

  • Allows users to upload a pic from their hard drive for storage on our server
  • Shrinks the image if it’s too big; expands it if it’s too small (height/width)

Is this easy to build yourself? Or is there already a library for it?

  • 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-18T09:11:09+00:00Added an answer on May 18, 2026 at 9:11 am

    To upload and store the image, I would recommend generating a random filename for the picture, instead of keeping the original file name. This will prevent conflicts and also add a measure of security. I would suggest a pretty long name; just random numbers and letters.

    Then, store the random file name in the database record along with your user info. This way, you won’t have to worry about file names and user names getting out of sync, and, as I said earlier, someone won’t be able to guess that Joe Schmoe’s profile picture is stored as JoeSchmoe.jpg.

    For when you get to the image-resizing part, use this function below I modified (from the PHP user comments). In your case, "images/smallerpicture.jpeg" would probably be replaced by "images/<some random name here>.jpeg".

    Example:

    scaleImage("images/bigpicture.jpeg", 100, 100, "images/smallerpicture.jpeg");
    

    Function:

    function scaleImage($source, $max_width, $max_height, $destination) {
        list($width, $height) = getimagesize($source);
        if ($width > 150 || $height > 150) {
            $ratioh = $max_height / $height;
            $ratiow = $max_width / $width;
            $ratio = min($ratioh, $ratiow);
            // New dimensions
            $newwidth = intval($ratio * $width);
            $newheight = intval($ratio * $height);
    
            $newImage = imagecreatetruecolor($newwidth, $newheight);
    
            $exts = array("gif", "jpg", "jpeg", "png");
            $pathInfo = pathinfo($source);
            $ext = trim(strtolower($pathInfo["extension"]));
    
            $sourceImage = null;
    
            // Generate source image depending on file type
            switch ($ext) {
            case "jpg":
            case "jpeg":
                $sourceImage = imagecreatefromjpeg($source);
                break;
            case "gif":
                $sourceImage = imagecreatefromgif($source);
                break;
            case "png":
                $sourceImage = imagecreatefrompng($source);
                break;
            }
    
            imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    
            // Output file depending on type
            switch ($ext) {
            case "jpg":
            case "jpeg":
                imagejpeg($newImage, $destination);
                break;
            case "gif":
                imagegif($newImage, $destination);
                break;
            case "png":
                imagepng($newImage, $destination);
                break;
            }
        }
    }
    

    It supports gifs, jpgs, and pngs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Oddly enough, googling this error doesn't produce any results. Is there any quick fix
$test = 'love'; $eff = end(explode('ov',$test)); I can't figure it out; oddly enough, this
You can set the Vim color scheme by issuing :colorscheme SCHEME_NAME but, oddly enough,
Oddly enough, most of this works as it has been written, however I'm not
There is a special character which can be seen here http://www.fileformat.info/info/unicode/char/1f4a9/index.htm I have the
(I know this is a sort of lazy question, but it's oddly hard to
Recently I started using OpenGL in C++ for some 3D rendering, but oddly enough
Oddly enough, my model passes validation just fine, and acts as expected, however I
I have an oddly difficult task to perform. I thought it would be easy,
I find some code sample with these oddl lines QList<TDataXml *> *newXMLData = input->getValue<QList<TDataXml

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.