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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:42:03+00:00 2026-05-14T06:42:03+00:00

I want to be able to retrieve a remote image from a webserver, resample

  • 0

I want to be able to retrieve a remote image from a webserver, resample it, and then serve it up to the browser AND save it to a file. Here is what I have so far:

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "$rURL");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
$out = curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

$imgRes = imagecreatefromstring($out);
imagejpeg($imgRes, $filename, 70);

header("Content-Type: image/jpg");
imagejpeg($imgRes, NULL, 70);
exit();

Update

Updated to reflect correct answer based on discussion below

  • 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-14T06:42:04+00:00Added an answer on May 14, 2026 at 6:42 am

    You can fetch the file into a GD resource using imagecreatefromstring():

    imagecreatefromstring() returns an image identifier representing the image obtained from the given data. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.

    from there, it’s pretty straightforward using imagecopyresampled().

    Output it using imagejpeg() or whichever output format suits you best.

    Make one output with a file name:

    imagejpeg($image_resource, "/path/to/image.jpg");
    

    then send the same resource to the browser:

    header("Content-type: image/jpeg");
    imagejpeg($image_resource);
    

    depending on the image’s format, you may want to use the imagepng() or imagegif() functions instead.

    You may want to work with different output formats depending on the input file type. You can fetch the input file type using getimagesize().

    Remember that you can adjust the resulting JPEG image’s quality using the $quality parameter. Default is 75% which can look pretty crappy.

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

Sidebar

Related Questions

I want to be able to send all the selected values from a listbox
I want to understand how the dynamic proxy stub implementation is actually done behind
I have an object, MySession , that has a hashtable for storing arbitrary properties
We are seeing Spring in school right now but we don't have the time
I want to do something like this List<Integer, String, String> I want to be
This should be pretty easy but I'm having a heck of a time doing
I really HATE to ask this because I thought this is supposed to be
I would like to implement a drawing class with the help of Quartz .
Let me illustrate this question with a simplified example. Assume I am building a
I am looking for a regex that can identify in a sentence that consecutive

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.