cgishack Posted April 19, 2007 Share Posted April 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/ Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 Can you show the jpeg to bytes array code, as it would be a simple matter of reversing it Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/#findComment-233249 Share on other sites More sharing options...
cgishack Posted April 19, 2007 Author Share Posted April 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/#findComment-233255 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 well if imagecreatefromstring isn't working then maybe try building a string from the array ie <?php $newimage = ""; foreach ($imageBytes as $b) { $newimage .= $b; } $img = imagecreatefromstring($newimage); ?> this is a pure guess Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/#findComment-233278 Share on other sites More sharing options...
cgishack Posted April 19, 2007 Author Share Posted April 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/#findComment-233289 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 Ahhh Old Header problem,, well we live and we learn Oh can you click solved please (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/47753-solved-create-image-from-bytes/#findComment-233294 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.