Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
convert jpg image to bytes
Old 03-08-2011, 09:22 AM convert jpg image to bytes
Skilled Talker

Posts: 97
Trades: 0
hello everyone..

please i want to know how i can convert my *.jpg image into bytes ??

i am searching online and i did not get any module or example that can solve this problem.
john_zakaria is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-08-2011, 09:42 AM Re: convert jpg image to bytes
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
They are already "bytes", that's how they can be stored digitally.

do you mean:

you want to encode into character data to embed in an email. (base64)
or
You want to stream it as binary data to a user-agent?
or
something else?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-08-2011, 09:48 AM Re: convert jpg image to bytes
Skilled Talker

Posts: 97
Trades: 0
Quote:
Originally Posted by chrishirst View Post
They are already "bytes", that's how they can be stored digitally.

do you mean:

you want to encode into character data to embed in an email. (base64)
or
You want to stream it as binary data to a user-agent?
or
something else?
in the following example there is a text that is converted to image all that i need is to make the opposite.


i have an image and i want to get the string like the variable $data
PHP Code:
<?php
$data 
'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
       
'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
       
'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
       
'8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data base64_decode($data);

$im imagecreatefromstring($data);
if (
$im !== false) {
    
header('Content-Type: image/png');
    
imagepng($im);
    
imagedestroy($im);
}
else {
    echo 
'An error occurred.';
}
?>
john_zakaria is offline
Reply With Quote
View Public Profile
 
Old 03-08-2011, 10:48 AM Re: convert jpg image to bytes
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://php.net/manual/en/function.base64-encode.php
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-09-2011, 01:46 AM Re: convert jpg image to bytes
Skilled Talker

Posts: 97
Trades: 0
Quote:
Originally Posted by chrishirst View Post

thanks alot for your help

the function is encoding my code well.. but
when i tried to show the encoded image it shows for me a string not the image itself.

can you help me to show it.. coz i am selecting it from databse as encoded string??

PHP Code:
$data file_get_contents('1A_Logo.JPG');
$data base64_encode($data); 
//echo $data;

$testbase64_decode($data);
echo 
$test
john_zakaria is offline
Reply With Quote
View Public Profile
 
Old 03-09-2011, 09:44 AM Re: convert jpg image to bytes
Skilled Talker

Posts: 60
Name: Dmitry
Trades: 0
Try this:
$image = file_get_contents('1A_Logo.JPG');
$data = base64_encode($image);
//echo $data;

$test= base64_decode($data);
echo
$test;
__________________
Sincerely, Dmitry

Please login or register to view this content. Registration is FREE
ElmanF is offline
Reply With Quote
View Public Profile Visit ElmanF's homepage!
 
Old 03-09-2011, 09:54 AM Re: convert jpg image to bytes
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
To display the encoded data as an image you have to send the content header that corresponds to the appropriate file type along with the data, so the useragent knows how to display it.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-10-2011, 08:39 AM Re: convert jpg image to bytes
Skilled Talker

Posts: 97
Trades: 0
Quote:
Originally Posted by chrishirst View Post
To display the encoded data as an image you have to send the content header that corresponds to the appropriate file type along with the data, so the useragent knows how to display it.

how i can know this header?
john_zakaria is offline
Reply With Quote
View Public Profile
 
Old 03-10-2011, 12:17 PM Re: convert jpg image to bytes
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.iana.org/assignments/media-types/index.html

http://www.w3schools.com/media/media_mimeref.asp

http://reference.sitepoint.com/html/mime-types-full
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to convert jpg image to bytes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.21713 seconds with 12 queries