472,328 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

How to convert a gif file to byte array? thanks!

i can read a gif to a string,

$file = 'IconValid.gif';
$image = fread(fopen($file,r),filesize($file));

but how can i get a byte array from gif file.

thanks in advance!
May 6 '09 #1
9 11086
code green
1,726 Expert 1GB
Not sure whar you are trying to do but what about
Expand|Select|Wrap|Line Numbers
  1. file_get_contents()
May 6 '09 #2
i hope it can return a byte array from gif file.
like $image = array(\x0d,\x08,\x02,\x0b,\x0c).
file_get_contents() only can return string, or how can i convert the string to array.

i need to access a web service to invoke a method, the method has a argument which type is byte[], so i need the array $image. any idea?
May 6 '09 #3
247 Expert 100+
i guess you want to alter the image after that?

problem with gif, jpg and png files is that they are encrypted to reduce size. if you really want every bit in an array, you'll need bitmaps. this means that you'll need to convert your image first.

then you can read the file as a string and use substring and split to get the data into an array.

even so, im not sure if thats possible
May 6 '09 #4
code green
1,726 Expert 1GB
Sorry I meant
Expand|Select|Wrap|Line Numbers
  1. file();
May 6 '09 #5
i've tried the function file(), it can return an string array, but it's invalid value for the web service. it need binary value.
Hi Ciary, can you show me some sample for your solution?
May 6 '09 #6
247 Expert 100+
like i said, i don't think it's possible. to see why: open a bmp-file with notepad or wordpad. you'll see it isnt that easy to read what color every pixel has. even if you do know what it looks like.

if you use fread(), you'll read the file as if it was a txt-file. therefore i dont think you can split it up.

what are you going to do with it on the webservice?
May 6 '09 #7
webservice can save the byte[] value to DB, and it only can be byte[]. i can't change t he webservice. so there is any other method to get the byte[] with php. can i load the gif file to memory, and then return the byte[] from memory?
May 6 '09 #8
code green
1,726 Expert 1GB
Are you tring to do a string to byte conversion as in .NET.
I don't think PHP has such low level control.
It is like this in C#
Expand|Select|Wrap|Line Numbers
  1. public static byte[] StrToByteArray(string str)
  2. {
  3.     System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
  4.     return encoding.GetBytes(str);
  5. }
May 6 '09 #9
247 Expert 100+
if you don't have access to the webservice, i don't think i can help you. i can't see a way to convert an image into a byte array using php. there was another way in which you stream your image to your webservice using SOAP and then do the conversion there.

you can always write your own webservice with the conversion to the array and then use a webservice in the webservice to write it into the DB. its a huge detour but it should work
May 6 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it...
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the...
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by...
by: Howard Weiss | last post by:
I am reading a file (containing short integers). To read the file, I use the following FileStream *myFile = new FileStream(FileName, ...
by: Dennis | last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte array containing the resulting JPEG Image as follows: Public Function...
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example ...
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile)...
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() =...
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string...
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.