473,394 Members | 2,071 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,394 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 26499
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.