473,574 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

4 New Member
i can read a gif to a string,

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

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

thanks in advance!
May 6 '09 #1
9 11364
code green
1,726 Recognized Expert Top Contributor
Not sure whar you are trying to do but what about
Expand|Select|Wrap|Line Numbers
  1. file_get_contents()
May 6 '09 #2
barmimor
4 New Member
i hope it can return a byte array from gif file.
like $image = array(\x0d,\x08 ,\x02,\x0b,\x0c ).
file_get_conten ts() 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
Ciary
247 Recognized Expert New Member
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 Recognized Expert Top Contributor
Sorry I meant
Expand|Select|Wrap|Line Numbers
  1. file();
May 6 '09 #5
barmimor
4 New Member
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
Ciary
247 Recognized Expert New Member
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
barmimor
4 New Member
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 Recognized Expert Top Contributor
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
Ciary
247 Recognized Expert New Member
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

1
4458
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 in the database. I use System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte...
6
10165
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 "byte array" into a string. the problem is that the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array)...
3
10353
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 combining bytes by pairs: My array: byte, byte, byte, etc. I need: short = byte+byte, short = byte+byte, etc.
2
2324
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, FileMode::Open, FileAccess::Read); __int64 myFileSize = myFile->get_Length(); Byte myFileData; myFile1Data = new Byte;
3
9203
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 BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As Long) As Byte() 'find the encoder with the image/jpeg mime-type dim codecs as ImageCodecInfo = ImageCodecInfo.GetImageEncoders() Dim ici As...
6
53692
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 Private mByte() as New Byte(4){11,22,33,44} Now how do I convert it to: dim myStr as string = "11,22,33,44"
5
3900
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) ) { int fileSize = (int)fs.Length; int buffer = fileSize; byte b = new byte;
8
5898
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() = appel.GetIDAsVariant("comm/datamodem") The vFileHandle is supposed to be a file handle (an IntPtr, I suppose). How can I convert this Byte() in this IntPtr ?
19
5319
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 itself. The difference with repr(object) is that str(object) does not always attempt to return a string that is acceptable to eval(); its goal is to return a printable string. If no argument is given,...
0
10745
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 java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not...
0
7828
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8260
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7840
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6493
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3765
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2257
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.