473,241 Members | 3,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Can PHP read an image file?

Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.
--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #1
12 26476
Randy Webb wrote:
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.


Yes, because PHP rocks! =)

The PHP manual has a bunch of info. on this topic.
http://www.php.net/image

Regards,

- Dan
http://www.dantripp.com/
Jul 17 '05 #2
"Randy Webb" <hi************@aol.com> wrote in message
news:xu********************@comcast.com...
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.
--
Randy
Chance Favors The Prepared Mind


Here you go, this one opens up a jpg file and spits out pixel by pixel.

at the moment, the output is send to screen, you can open a file and dump it
there instead if you wish.

the output is row by row, and 6 chr hex color
format:
rrggbbrrggbbrrggbb

<?php

$imgFile = "icon_ar.jpg";

$im = imagecreatefromjpeg($imgFile);

$imgWidth = imagesx($im);
$imgHeight = imagesy($im);
print " File: $imgFile\n";
print " Width: $imgWidth\n";
print "Height: $imgHeight\n";
print "Format: red:green:blue\n";
print "\n";

for ($y=0; $y < $imgHeight; $y++)
{
for ($x=0; $x < $imgWidth; $x++)
{
$ndx = imagecolorat($im,$x,$y);
$aryColors = imagecolorsforindex($im,$ndx);
print substr("0".dechex($aryColors['red']),-2);
print substr("0".dechex($aryColors['green']),-2);
print substr("0".dechex($aryColors['blue']),-2);
}
print "\n";
}

?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3
See my earlier post about a BMP to GD converter. There's code in there that
decodes a BMP file. Instead of packing the bytes into a GD scan line, append
it to a line of text instead.

http://groups.google.com/groups?hl=e...fe=off&selm=a1
64f4b5.0311302128.40fb37f4%40posting.google.com

Uzytkownik "Randy Webb" <hi************@aol.com> napisal w wiadomosci
news:xu********************@comcast.com...
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.
--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #4
Hmm, I do not know if this is the right place to post this, but after I did
that small piece of code for you I tweeked it and did an image 2 text, sorta
lika an ascii art.

check it out:
http://www.gzentools.com/test/img2text.php

the source is here:
http://www-3.gzentools.com/snippetvi...v=img2text.php
--
Mike Bradley
http://www.gzentools.com -- free online php tools
"CountScubula" <me@scantek.hotmail.com> wrote in message
news:zM*****************@newssvr25.news.prodigy.co m...
"Randy Webb" <hi************@aol.com> wrote in message
news:xu********************@comcast.com...
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.
--
Randy
Chance Favors The Prepared Mind

Here you go, this one opens up a jpg file and spits out pixel by pixel.

at the moment, the output is send to screen, you can open a file and dump

it there instead if you wish.

the output is row by row, and 6 chr hex color
format:
rrggbbrrggbbrrggbb

<?php

$imgFile = "icon_ar.jpg";

$im = imagecreatefromjpeg($imgFile);

$imgWidth = imagesx($im);
$imgHeight = imagesy($im);
print " File: $imgFile\n";
print " Width: $imgWidth\n";
print "Height: $imgHeight\n";
print "Format: red:green:blue\n";
print "\n";

for ($y=0; $y < $imgHeight; $y++)
{
for ($x=0; $x < $imgWidth; $x++)
{
$ndx = imagecolorat($im,$x,$y);
$aryColors = imagecolorsforindex($im,$ndx);
print substr("0".dechex($aryColors['red']),-2);
print substr("0".dechex($aryColors['green']),-2);
print substr("0".dechex($aryColors['blue']),-2);
}
print "\n";
}

?>

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #5
CountScubula wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:xu********************@comcast.com...
Running Apache2 and PHP 4.3.3 on Windows, is there any way that I can
have PHP read an image file and out put its color content?

Preferably, I would like for it to read a .bmp file and output a text
file of the color codes for each pixel of the image.
I can convert it to a .jpg or a .gif if need be, but I would prefer to
stay with the .bmp if its possible.

Any help is greatly appreciated.
--
Randy
Chance Favors The Prepared Mind

Here you go, this one opens up a jpg file and spits out pixel by pixel.

at the moment, the output is send to screen, you can open a file and dump it
there instead if you wish.

the output is row by row, and 6 chr hex color
format:
rrggbbrrggbbrrggbb

<?php

$imgFile = "icon_ar.jpg";

$im = imagecreatefromjpeg($imgFile);


With PHP 4.3.3, it gives me an error on that line.
Call to undefined function: imagecreatefromjpeg()
I am assuming it means I need GD for this to work?
If so, is there an FAQ type directions to installing GD?
--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #6
Chung Leong wrote:
See my earlier post about a BMP to GD converter. There's code in there that
decodes a BMP file. Instead of packing the bytes into a GD scan line, append
it to a line of text instead.

http://groups.google.com/groups?hl=e...fe=off&selm=a1
64f4b5.0311302128.40fb37f4%40posting.google.com


I had actually found that thread in researching an answer to this, and
assumed I needed GD for it to work, and seem to lack the common sense
required to get GD to work.
--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #7
"Randy Webb" <hi************@aol.com> wrote in message
news:XN********************@comcast.com...
With PHP 4.3.3, it gives me an error on that line.
Call to undefined function: imagecreatefromjpeg()
I am assuming it means I need GD for this to work?
If so, is there an FAQ type directions to installing GD?
--
Randy
Chance Favors The Prepared Mind


hmm, talk to your hosting company, this is a simple lib that, in my opionion
should be installed to do anything usefull with images, or get a new hosting
company
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #8
CountScubula wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:XN********************@comcast.com...
With PHP 4.3.3, it gives me an error on that line.
Call to undefined function: imagecreatefromjpeg()
I am assuming it means I need GD for this to work?
If so, is there an FAQ type directions to installing GD?

hmm, talk to your hosting company, this is a simple lib that, in my opionion
should be installed to do anything usefull with images, or get a new hosting
company


I am the hosting company. Well, sort of. Its a local copy of Apache and
PHP that I installed to try to learn PHP.

--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #9
>
I am the hosting company. Well, sort of. Its a local copy of Apache and
PHP that I installed to try to learn PHP.

--
Randy
Chance Favors The Prepared Mind


I take it this is a windows copy?

I have not used this for a long time, I hear if you download the zip, not
the installer, you will have lots-o-.dll's to go with it, just copy the
correct one over to your machine, I think you may have to do something in
the .ini file as well

--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #10
are you using linux or windows ? maybe i could help you

If you are using linux, you have to install the GD library and recompile php
with GD support.

If you are using windows, and you dl php from php.net, GD is already
configured to work, just fallow the instruction again to see what you have
missing. The library is gd.dll, it's located in the extension directory in
php, it's already configured to work from here.

GD can be found here http://www.boutell.com/gd/

Savut

"CountScubula" <me@scantek.hotmail.com> wrote in message
news:L9*****************@newssvr27.news.prodigy.co m...

I am the hosting company. Well, sort of. Its a local copy of Apache and
PHP that I installed to try to learn PHP.

--
Randy
Chance Favors The Prepared Mind


I take it this is a windows copy?

I have not used this for a long time, I hear if you download the zip, not
the installer, you will have lots-o-.dll's to go with it, just copy the
correct one over to your machine, I think you may have to do something in
the .ini file as well

--
Mike Bradley
http://www.gzentools.com -- free online php tools

Jul 17 '05 #11
Randy Webb wrote:
Chung Leong wrote:
See my earlier post about a BMP to GD converter. There's code in there
that
decodes a BMP file. Instead of packing the bytes into a GD scan line,
append
it to a line of text instead.

http://groups.google.com/groups?hl=e...fe=off&selm=a1

64f4b5.0311302128.40fb37f4%40posting.google.com

I had actually found that thread in researching an answer to this, and
assumed I needed GD for it to work, and seem to lack the common sense
required to get GD to work.


I have it working now, thank you :)

--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #12
Savut wrote:
are you using linux or windows ? maybe i could help you

If you are using linux, you have to install the GD library and recompile php
with GD support.

If you are using windows, and you dl php from php.net, GD is already
configured to work, just fallow the instruction again to see what you have
missing. The library is gd.dll, it's located in the extension directory in
php, it's already configured to work from here.

GD can be found here http://www.boutell.com/gd/

Thanks. A post in another thread "GD on PHP", directed me on how to
enable it, and now is working. And yes, its a Windows (ME) machine.

Without me replying to each and all, thanks to everybody who helped me
with it :)
--
Randy
Chance Favors The Prepared Mind

Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phil Powell | last post by:
I have a PHP script that would read in a binary file and display it as if it were <img src>, how would you do that w/o changing the header's MIME type? The entire file does not need to be changed....
1
by: Thomas | last post by:
Hi all, Is there a faster way to read image dimensions other than something like: ImageOrig = System.Drawing.Image.FromFile(Filepath); ImageOrigHeight = ImageOrig.Height; ImageOrigWidth =...
3
by: Paul Loveless | last post by:
Hi all, I would like to create a routine that retrieves specific properties from an image file (ex. a jpeg) without having to open the file. For example, in WinXP when you right-click a jpg file...
1
by: Daniel Mark | last post by:
Hello all: I have following code that works well under command line, but it doesn't work after I convert it as exe application. ############### file: testPath.py import getopt, math, sys,...
3
by: Raghu Raman | last post by:
Hi i want to save the read the image file and show it on a image control of a mobile webform .But the mobile control does not support html images ,so i am forced to use the server image control...
4
by: abumarwah | last post by:
im new in this area using c++, and i want to write program read image and display it in form of array or matrix
70
by: quickcur | last post by:
hi can anyone explain me to read image to memory from a url it is very easy in java but it is hard to find an complete solution in c/c++. Thanks,
2
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.