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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:24:19+00:00 2026-06-12T10:24:19+00:00

How do you download, resize and store an image from a remote server using

  • 0

How do you download, resize and store an image from a remote server using php?
This is the code I am using

$temp_image = file_get_contents($url);
$image = imagecreatefromstring($temp_image);
$thumb = imageToCanvas($image,100,75,true);
imagejpeg($thumb,$base_image_path . $thumb_path,90)


function imageToCanvas($_image, $_canvasWidth, $_canvasHeight, $forceScale=false,$x=false,$y=false) 
{
    $newImage = imagecreatetruecolor($_canvasWidth, $_canvasHeight);
    $imageinfo = getimagesize($_image);
    $sourceWidth = $imageinfo[0];
    $sourceHeight = $imageinfo[1];  
    $sourceImage = openImage($_image);
    imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $_canvasWidth, $_canvasHeight, $sourceWidth, $sourceHeight);
    return $newImage;
}

function openImage($file) 
{
 // *** Get extension
 $extension = strtolower(strrchr($file, '.'));
 switch($extension) {
   case '.jpg': case '.jpeg':
     $img = @imagecreatefromjpeg($file);
     break;
   case '.gif':
    $img = @imagecreatefromgif($file);
     break;
   case '.png':
     $img = @imagecreatefrompng($file);
     break;
   default:
     $img = false;
     break;
 }
 return $img; 
}

Doesn’t work and I don’t know why.

$sourceWidth & $sourceHeight doesn’t have a value so I presume $image is in the wrong format

Thanks!

  • 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-06-12T10:24:21+00:00Added an answer on June 12, 2026 at 10:24 am

    There is no function in php called openImage so that would be a problem if you don’t define it yourself.

    If you do have it defined, what does it look like and are you receiving any errors?

    Edit: Based on your comments the problem would seem to be that you treat the input parameter of your openImage function as a file path. However, when you call it you are feeding it an image resource, the result of imagecreatefromstring.

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

Sidebar

Related Questions

Using the code below each image download) file_get_contents() ) takes on average 8-15 seconds.....
I'm using AFNetworking to pull images from a URL, resize, store to disk and
I download an image from a url to an ec2 instance(wget), process it with
I've been looking for a way to download an image from a URL, preform
i am trying to download a image file using ftp, on every code i
I download gcc-code-assist from here , then do make and sudo make install. After
I use following code to resize the image after i upload it. function re-sizes
I have method that download and resize image according to screen size to fit
I have this JPEG that has been giving problems to the function imagesx($this->image) from
I want to resize my image when I am downloading it, or after download.

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.