Jump to content

[SOLVED] read in file contents of an image file


The Little Guy

Recommended Posts

Is there a better way to read in an image file? I currently have this:

 

$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $furl);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

// Getting binary data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

$image = curl_exec($ch);

 

 

I want to use imagecreatefromstring but with the way I have it, there will be way too many server file requests...

 

I tried using fread, but that didn't work for some reason, that only read in some of the file, and I don't know why...

 

 

Thanks!

That is one too many...

 

Yeah but I also use an image tag to call this file, so to build one image there is a total of 2 requests to the server, and there is a minimum of 5 of these images on some pages, which totals 10 requests for those.

Well, if a book is at the library and you want to read it, how do you do that? You go get the book. Same thing here. You cannot read the binary data of the image without downloading it. First you download it, next the client does. Why are you downloading it anyway?

I am making a PHP image, the image builds fine, Its just that I am making 2 http requests to the server for one image:

 

1. an image tag to get the PHP file

2. a cURL request in the php file to get the image

 

I should only have to make one HTTP request to the server, and that should be for the image tag. The getting of the image should all be done on the server, and using fopen and fread does not make a secondary request to the server, which is what I want to do.

With your library example to get the book one time you don't have to go to the library 2 times to get the book once, which is happening here.

 

I'm starting to thing I did fopen/fread wrong, but maybe I am wrong...

 

OK I checked, and I'm doing fopen/fread the same, but now it is working...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.