Jump to content

[SOLVED] Create Image From Bytes


cgishack

Recommended Posts

Hello,

I have a web service returning me an Array of Bytes in the form of a Jpg.

I am trying to us the GD lib to create the image.

 

Here is my code ($imageBytes is the array of Bytes)

//Create the image from Bytes to JPEG.
$img = imagecreatefromstring($imageBytes);
header('Content-Type: image/JPEG');
header("Content-Length: " .strlen($imageBytes));
imagejpeg($img);

 

But the image is not displaying.

 

Should I use GD, or should I use something else.

Any ideas what I am doing wrong.

Link to comment
https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/
Share on other sites

Well I get it from a web service

Like so..

 

$fixedSizeReturn = $client->WarehouseExtractRadiusFixedSize_v1($radiusSize);
$imageBytes = $fixedSizeReturn->WarehouseExtractRadiusFixedSize_v1Result->Result->Image->ImageBytes;

 

The documentation says

"Returns an image as a JPEG as an array of bytes"

 

I have done it in ASP.NET like so

        Response.ContentType = "image/JPEG";
        Response.AppendHeader("Content-Length", imageBytes.Length.ToString());
        Response.Cache.SetLastModified(DateTime.Now);
        Response.Cache.SetCacheability(HttpCacheability.Public);
        Response.BinaryWrite(imageBytes);

 

But, now I need to do the same thing in PHP

 

Drew

You know what my problem was.....

 

I had white space in my php file at the top..

So <php should have been on line 0 but I had it on line 10

 

I never thought that would matter,  but it did.

Maybe passes extra bytes  to the file.

 

Thanks for all your help.

 

Drew

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.