-3

Possible Duplicate:
Parse a text file containing image data

Here is my code for getting image data from a text file:

while (!feof($fh)) {
    $line = fgets($fh);
    $lines[] = $line;
    $match1 ="/^[0-9]{1,3},[0-9]{1,3}/";
    $match2 = "/[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},(?:,?[0-9]{1,3})*(?:\.[0-9]{1,10})?\b/";

    $parts  = preg_match($match1, $line, $regs);
    $parts2 = preg_match($match2, $line, $regs2);
    foreach($regs as $key => $lame) {
        $lamer[] = $lame;
    }
    foreach($regs2 as $key => $lame2) {
        $lamer2[] = $lame2;
    }
}

The first preg_match gets the coords, and second gets the rgba() data. I'm trying to put this into a javascript array but I am getting this error:

SyntaxError: too many constructor arguments

I assume it's too much data for the javascript array.

Now I am wondering how or if I can skip data in the array, namely the the coords that have a rgba with 0 alpha, which would mean that I would have to skip both.

I'm also wondering if I should try to combine the two matches into one to see if that would make it easier, but I'm not sure how to do that.

Here's the data I am working with that is a 300x180 image:

41,6:  (255,255,255,  0)  #FFFFFF00  srgba(255,255,255,0)
42,6:  (255,255,255,  0)  #FFFFFF00  srgba(255,255,255,0)
90,35: ( 77, 80, 12, 98)  #4D500C62  srgba(77,80,12,0.384314)
91,35: ( 95, 99, 13, 78)  #5F630D4E  srgba(95,99,13,0.305882)
92,35: ( 96, 99, 31, 90)  #60631F5A  srgba(96,99,31,0.352941)
93,35: (106,110, 14, 68)  #6A6E0E44  srgba(106,110,14,0.266667)
94,35: ( 95, 99, 13, 78)  #5F630D4E  srgba(95,99,13,0.305882)
Community
  • 1
  • 1

1 Answers1

0

Use JavaScript RegExp pattern

^(\\d+),(\\d+)[^#]+#.{6}(?!00)[^(]+\\((\\d+),(\\d+),(\\d+),(\\d*(?:\\.\\d*)?)

Check this demo.

Ωmega
  • 42,614
  • 34
  • 134
  • 203