logo
down
shadow

how to get image from curl


how to get image from curl

By : Lotaku
Date : November 19 2020, 12:41 AM
will be helpful for those in need Your script is correctly written. I have tried and works fine, but you need to set image headers in order to let navigator show the image.
Example:
code :
header("Content-Type: image/jpeg");

$url = 'https://images.nga.gov/en/web_images/constable.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11');
$res = curl_exec($ch);
$rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch) ;
echo $res;


Share : facebook icon twitter icon
Output external image with cURL, but how do you change the width of the image?

Output external image with cURL, but how do you change the width of the image?


By : Godream
Date : March 29 2020, 07:55 AM
hop of those help? If the image is heading for a browser inside an tag, then you can get the browser to rescale it by changing the width attribute.
Otherwise you need to grab the file and rescale it in your PHP code before outputting it.
code :
$img = @imagecreatefromstring($file);

if ($img === false) {
    echo $file;
    exit;
}

$width = imagesx($img);
$height = imagesy($img);

$newWidth = 300;

$ratio = $newWidth / $width;
$newHeight = $ratio * $height;


$resized = @imagecreatetruecolor($newWidth, $newHeight);

if ($resized === false) {
    echo $file;
    exit;
}

$quality = 90;

if (@imagecopyresampled($resized, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height)) {
    @imagejpeg($resized, NULL, $quality);
} else {
    echo $file;
}
Image upload CURL command to PHP Curl

Image upload CURL command to PHP Curl


By : Hillary Rose
Date : March 29 2020, 07:55 AM
around this issue I fixed the issue myself. Had to use php curl file create to make it work instead of appending with '@'
http://www.php.net/manual/es/function.curl-file-create.php
Check if image file is available in curl when save facebook profile image. PHP

Check if image file is available in curl when save facebook profile image. PHP


By : Will
Date : March 29 2020, 07:55 AM
I hope this helps you . You can always check curl returned header info with curl_getinfo() (more at php.net)
So in your case you can curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD) to see how much bytes are returned.
Saving and image to server from a URL using cURL results in a blank image

Saving and image to server from a URL using cURL results in a blank image


By : Ramaraja
Date : March 29 2020, 07:55 AM
I hope this helps . Try using "w" instead of "wb" $fp = fopen('./logo.jpg', 'w'); Or try: file_put_contents('./logo.jpg',$rawdata); (not sure it is binary safe, should be)
And
code :
$info = var_export(curl_getinfo($ch),true);
file_put_contents('log.txt',$info);
header('content-type: text/plain');
var_export(curl_getinfo($ch));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_ENCODING,"");   
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
curl_setopt($ch, CURLOPT_VERBOSE, true);

$data = curl_exec($ch);
if (curl_errno($ch)){
    echo ' Retrieve Base Page Error: ' . curl_error($ch);
}
else {
  $info = rawurldecode(var_export(curl_getinfo($ch),true));
  $skip = intval(curl_getinfo($ch, CURLINFO_HEADER_SIZE)); 
  $responseHeader= substr($data,0,$skip);
  $data= substr($data,$skip);
  echo "HEADER: $responseHeader\n";
  echo "\n\nINFO: $info\n\nDATA: $data";
}  
Submitting an image to Flask via curl fails with "not enough image data'

Submitting an image to Flask via curl fails with "not enough image data'


By : user3554871
Date : March 29 2020, 07:55 AM
may help you . The pillow Image.fromarray method expects a raw bytemap as input, and will not work when given encoded pixel bytes like e.g. the PNG-encoded pixels in this example. The correct way to handle this case is to use BytesIO and Image.open instead:
code :
with open('test_image_512.png', 'rb') as f:
    img_b = f.read()
Image.open(BytesIO(img_b))
Related Posts Related Posts :
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org