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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:27:21+00:00 2026-05-25T23:27:21+00:00

ive done my research on the net and here as well and i keep

  • 0

ive done my research on the net and here as well and i keep on coming up with no answer that can help me:
i have the below code which displays an image from a folder based on a user’s location however the image is too big and i need to resize it.
all the scripts that i have tried or read relate to files being uploaded. can anyone push me in the right direction?

thank you.

 <?php


        print"  

        <table  <td width=\"138\" height=\"73\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
      <tr>
        <td align=\"center\" valign=\"middle\"><a href=\"map.php\"><img src=\"" .
         esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') .
         "\" alt=\"Map of systems around {$user['location']}\" /></a></td>
      </tr>
    </table>
         "
    ?>

My problem arises from the fact that i need to pull the images as:

<img src=\"" .esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') . "\" alt=\"Map of systems around {$user['location']}\" /></a>
  • 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-25T23:27:22+00:00Added an answer on May 25, 2026 at 11:27 pm

    Wrote a tutorial about this a while ago. Perhaps it can help. It starts with uploading, but most of it is about resizing. Just swap out the usage of the $_FILES array by geting the image type and file name a different way. Here’s the code you should need:

    // Create image from file
    switch(strtolower($_FILES['image']['type']))
    {
         case 'image/jpeg':
             $image = imagecreatefromjpeg($_FILES['image']['tmp_name']);
             break;
         case 'image/png':
             $image = imagecreatefrompng($_FILES['image']['tmp_name']);
             break;
         case 'image/gif':
             $image = imagecreatefromgif($_FILES['image']['tmp_name']);
             break;
         default:
             exit('Unsupported type: '.$_FILES['image']['type']);
    }
    
    // Target dimensions
    $max_width = 240;
    $max_height = 180;
    
    // Get current dimensions
    $old_width  = imagesx($image);
    $old_height = imagesy($image);
    
    // Calculate the scaling we need to do to fit the image inside our frame
    $scale      = min($max_width/$old_width, $max_height/$old_height);
    
    // Get the new dimensions
    $new_width  = ceil($scale*$old_width);
    $new_height = ceil($scale*$old_height);
    
    // Create new empty image
    $new = imagecreatetruecolor($new_width, $new_height);
    
    // Resize old image into new
    imagecopyresampled($new, $image, 
         0, 0, 0, 0, 
         $new_width, $new_height, $old_width, $old_height);
    
    // Catch the imagedata
    ob_start();
    imagejpeg($new, NULL, 90);
    $data = ob_get_clean();
    
    // Destroy resources
    imagedestroy($image);
    imagedestroy($new);
    
    // Set new content-type and status code
    header("Content-type: image/jpeg", true, 200);
    
    // Output data
    echo $data;
    

    If you want to store the image as a file rather than dumping it to the browser, remove the head and echo part at the end and then swap out the NULL parameter in the imagejpeg call with an actual filename. Hope that helps 🙂

    Here’s the code in use: http://samples.geekality.net/image-resize/

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

Sidebar

Related Questions

I have a .net windows service that works it's way through a queue of
Problem I'm trying to create an CUDA application that is well integrated with .net.
ive just done so much research and tried so much but nothing works. I
I've done zero research on this, I'm just curious. The OutputCacheAttribute class in ASP.NET
Good day, I've done some research looking for this answer, but haven't had much
I've done a little research on hash tables, and I keep running across the
I've did some research. I've found that you can serialize then unserialize to get
I've done a few hours of additional research but I still can't find a
I've done a good bit of research to find an upload component for .NET
I have a .NET 4 website in VS2010 stored in a TFS 2010 team

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.