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 12 26311
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/
"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
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
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
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
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
"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
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
> 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
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
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
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 This discussion thread is closed Replies have been disabled for this discussion. Similar topics
7 posts
views
Thread by Phil Powell |
last post: by
|
1 post
views
Thread by Thomas |
last post: by
|
3 posts
views
Thread by Paul Loveless |
last post: by
|
1 post
views
Thread by Daniel Mark |
last post: by
|
3 posts
views
Thread by Raghu Raman |
last post: by
| |
70 posts
views
Thread by quickcur |
last post: by
| | | | | | | | | | | | |