Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Alex Nikitin
Absolutely agreed. A part of what i was asking deals with what he is
actually doing...

--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late.  ~Seymour Cray



On Mon, Jan 23, 2012 at 9:37 PM, Robert Cummings  wrote:
> On 12-01-23 09:29 PM, Alex Nikitin wrote:
>>
>> Have you done image processing? In my experience, with image
>> generation, photography and processing, typically you are bound by
>> resources when processing large amount of files than your connection,
>> or sometimes even disk io.
>
>
> It really depends on what you're doing with images, if it's intensive
> processing that's already implemented in the gd or imagick library to which
> you can just punt, then how much overhead do you think PHP is really going
> to add since these are C implemented libraries? Sure, if you are
> manipulating pixels one by one within your PHP code you may be running into
> resource issues, but for scaling images, or cropping, or even clipping and
> overlaying... you're not usually doing a whole lot within PHP itself. The
> love is happening in the C code in these cases. This is why when working
> with these libs you get a resource handle and not a string. The resource
> handle almost certainly maps to a native GD or imagick structure.
>
>
> Cheers,
> Rob.
> --
> E-Mail Disclaimer: Information contained in this message and any
> attached documents is considered confidential and legally protected.
> This message is intended solely for the addressee(s). Disclosure,
> copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Robert Cummings

On 12-01-23 09:29 PM, Alex Nikitin wrote:

Have you done image processing? In my experience, with image
generation, photography and processing, typically you are bound by
resources when processing large amount of files than your connection,
or sometimes even disk io.


It really depends on what you're doing with images, if it's intensive 
processing that's already implemented in the gd or imagick library to 
which you can just punt, then how much overhead do you think PHP is 
really going to add since these are C implemented libraries? Sure, if 
you are manipulating pixels one by one within your PHP code you may be 
running into resource issues, but for scaling images, or cropping, or 
even clipping and overlaying... you're not usually doing a whole lot 
within PHP itself. The love is happening in the C code in these cases. 
This is why when working with these libs you get a resource handle and 
not a string. The resource handle almost certainly maps to a native GD 
or imagick structure.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Alex Nikitin
Have you done image processing? In my experience, with image
generation, photography and processing, typically you are bound by
resources when processing large amount of files than your connection,
or sometimes even disk io.

--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late.  ~Seymour Cray



On Mon, Jan 23, 2012 at 7:51 PM, Robert Cummings  wrote:
> On 12-01-23 01:32 PM, Alex Nikitin wrote:
>>
>> If you don't mind me asking, if you want performance, which is kind of
>> essential if you are processing a large number of files, why are you
>> doing it in PHP?
>>
>> --
>> The trouble with programmers is that you can never tell what a
>> programmer is doing until it’s too late.  ~Seymour Cray
>
>
> Hi Alex,
>
> If you're processing a large number of files, the bottleneck could just as
> likely be the hard drive read/write and not so much PHP. And what's a large
> number of files? 50? 100? 1000? 100? Remember, PHP internal functions
> are usually wrappers around compiled C code... the shuffling around in the
> PHP engine itself can be quite tiny.
>
> Cheers,
> Rob.
> --
> E-Mail Disclaimer: Information contained in this message and any
> attached documents is considered confidential and legally protected.
> This message is intended solely for the addressee(s). Disclosure,
> copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Robert Cummings

On 12-01-23 01:32 PM, Alex Nikitin wrote:

If you don't mind me asking, if you want performance, which is kind of
essential if you are processing a large number of files, why are you
doing it in PHP?

--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late.  ~Seymour Cray


Hi Alex,

If you're processing a large number of files, the bottleneck could just 
as likely be the hard drive read/write and not so much PHP. And what's a 
large number of files? 50? 100? 1000? 100? Remember, PHP internal 
functions are usually wrappers around compiled C code... the shuffling 
around in the PHP engine itself can be quite tiny.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Alex Nikitin
If you don't mind me asking, if you want performance, which is kind of
essential if you are processing a large number of files, why are you
doing it in PHP?

--
The trouble with programmers is that you can never tell what a
programmer is doing until it’s too late.  ~Seymour Cray

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Nicholas Cooper
On 23 January 2012 14:34, Matijn Woudt  wrote:
> On Mon, Jan 23, 2012 at 3:26 PM, Nicholas Cooper  
> wrote:
>> On 23 January 2012 13:26, Matijn Woudt  wrote:
>>> On Mon, Jan 23, 2012 at 1:51 PM, Nicholas Cooper  
>>> wrote:
 Hi everyone,

 I've created an image in RGB from ImageMagick, it's 4 by 4 so I'm
 expecting 48 numbers (4*4*3). [width*height*(R,G,B)]

 When I read the file with PHP and unpack it I get between 330 and 333,
 I guess this difference is down to headers and end of file data.  Is
 there anyway to access only the useful image bits, those 48 numbers?

 Thank you,

 Nicholas Cooper

>>>
>>> Hi,
>>>
>>> The easiest way is probably using imagecolorat[1]. Just do a nested
>>> for loop over x and y values, and call imagecolorat for each pixel.
>>>
>>> Matijn
>>>
>>> [1] www.php.net/imagecolorat
>>
>> Thank you that does the trick and gives the expected output.  I plan
>> to be processing a large number of images and have always been wary of
>> using the built in image functions for performance reasons.  So if
>> there is any other solutions I'm welcome to them, or even if someone
>> just wants to say that performance is not such an issue any more.
>
>
> If the image you want to process is a simple bitmap (.bmp) file, then
> you can easily parse it yourself. Wikipedia has a page on the file
> format [1].
>
> In short, fopen your file, fseek to 0x000A, read 4 bytes, and parse
> them as little-endian (with unpack or so). fseek to that value, and
> then you can read 4*4*3 bytes with fseek. That is your RGB data, if it
> is in that format ofcourse. If you're not sure which format they are
> you might need to parse more of the BMP header, but that's up to you.
>
> Matijn
>
> [1] http://en.wikipedia.org/wiki/BMP_file_format

Thank you, I haven't quite managed to find the start of my 16 bytes,
but I get the idea, so I should be able to get this working after
reading more about the format.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Matijn Woudt
On Mon, Jan 23, 2012 at 3:26 PM, Nicholas Cooper  wrote:
> On 23 January 2012 13:26, Matijn Woudt  wrote:
>> On Mon, Jan 23, 2012 at 1:51 PM, Nicholas Cooper  
>> wrote:
>>> Hi everyone,
>>>
>>> I've created an image in RGB from ImageMagick, it's 4 by 4 so I'm
>>> expecting 48 numbers (4*4*3). [width*height*(R,G,B)]
>>>
>>> When I read the file with PHP and unpack it I get between 330 and 333,
>>> I guess this difference is down to headers and end of file data.  Is
>>> there anyway to access only the useful image bits, those 48 numbers?
>>>
>>> Thank you,
>>>
>>> Nicholas Cooper
>>>
>>
>> Hi,
>>
>> The easiest way is probably using imagecolorat[1]. Just do a nested
>> for loop over x and y values, and call imagecolorat for each pixel.
>>
>> Matijn
>>
>> [1] www.php.net/imagecolorat
>
> Thank you that does the trick and gives the expected output.  I plan
> to be processing a large number of images and have always been wary of
> using the built in image functions for performance reasons.  So if
> there is any other solutions I'm welcome to them, or even if someone
> just wants to say that performance is not such an issue any more.


If the image you want to process is a simple bitmap (.bmp) file, then
you can easily parse it yourself. Wikipedia has a page on the file
format [1].

In short, fopen your file, fseek to 0x000A, read 4 bytes, and parse
them as little-endian (with unpack or so). fseek to that value, and
then you can read 4*4*3 bytes with fseek. That is your RGB data, if it
is in that format ofcourse. If you're not sure which format they are
you might need to parse more of the BMP header, but that's up to you.

Matijn

[1] http://en.wikipedia.org/wiki/BMP_file_format

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Nicholas Cooper
On 23 January 2012 13:26, Matijn Woudt  wrote:
> On Mon, Jan 23, 2012 at 1:51 PM, Nicholas Cooper  
> wrote:
>> Hi everyone,
>>
>> I've created an image in RGB from ImageMagick, it's 4 by 4 so I'm
>> expecting 48 numbers (4*4*3). [width*height*(R,G,B)]
>>
>> When I read the file with PHP and unpack it I get between 330 and 333,
>> I guess this difference is down to headers and end of file data.  Is
>> there anyway to access only the useful image bits, those 48 numbers?
>>
>> Thank you,
>>
>> Nicholas Cooper
>>
>
> Hi,
>
> The easiest way is probably using imagecolorat[1]. Just do a nested
> for loop over x and y values, and call imagecolorat for each pixel.
>
> Matijn
>
> [1] www.php.net/imagecolorat

Thank you that does the trick and gives the expected output.  I plan
to be processing a large number of images and have always been wary of
using the built in image functions for performance reasons.  So if
there is any other solutions I'm welcome to them, or even if someone
just wants to say that performance is not such an issue any more.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reading only RGB portion of an image, file_get_conents minus file headers etc

2012-01-23 Thread Matijn Woudt
On Mon, Jan 23, 2012 at 1:51 PM, Nicholas Cooper  wrote:
> Hi everyone,
>
> I've created an image in RGB from ImageMagick, it's 4 by 4 so I'm
> expecting 48 numbers (4*4*3). [width*height*(R,G,B)]
>
> When I read the file with PHP and unpack it I get between 330 and 333,
> I guess this difference is down to headers and end of file data.  Is
> there anyway to access only the useful image bits, those 48 numbers?
>
> Thank you,
>
> Nicholas Cooper
>

Hi,

The easiest way is probably using imagecolorat[1]. Just do a nested
for loop over x and y values, and call imagecolorat for each pixel.

Matijn

[1] www.php.net/imagecolorat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php