Convert Image to Array of bytes in PHP

Discussion in 'PHP' started by ivan.kristianto, Jul 2, 2009.

  1. #1
    Hi everyone,
    i want to process image byte in PHP.
    Does anyone know how to convert image to array of bytes in PHP?
    Thanks.

    Ivan
     
    ivan.kristianto, Jul 2, 2009 IP
  2. livedating

    livedating Active Member

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    83
    #2
    I would suggest to use imagecolorat:

    
    $img_ar = array();
    $im = imagecreatefromjpeg('/path/to/image.jpg');
    if (! $im) die("cant load image");
    for ($x=0; $x<imagesx($im); $x++) {
      for ($y=0; $y<imagesy($im); $y++) {
        $img_ar[$x][$y] = imagecolorat($im, $x, $y);
      }
    }
    
    // process $img_ar
    
    
    Code (markup):
    But probably it is better to use imagecolorat directly.
     
    livedating, Jul 2, 2009 IP
  3. ivan.kristianto

    ivan.kristianto Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    thanks livedatesearch,
    i will try it.
    But it realize thats a GD library.
    i wonder if imagick can do the same. or do you have any idea?
     
    ivan.kristianto, Jul 2, 2009 IP