help on image header

Discussion in 'PHP' started by warriorvow, Jul 1, 2007.

  1. #1
    i have a web service and accessing it is done thru query string. how
    to access a certain header field using php? the sample program i saw
    was done in java and it goes like this:

    String shortcutcode = connection.getHeaderField("ShortCut");
    ByteArrayInputStream bis = new ByteArrayInputStream (imageBytes,
    0,imageBytes.length);
    BufferedImage bim = ImageIO.read(bis);
    bim = bim.getSubimage(0,0,bim.getWidth(),bim.getHeight()-12);


    how to do the same in php?
     
    warriorvow, Jul 1, 2007 IP
  2. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #2
    please provide more details .. i dont seem to understand what you exactly mean..
     
    killerj, Jul 1, 2007 IP
  3. warriorvow

    warriorvow Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    actually i was able to get the desired string from the returned header by this way:

    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt($ch, CURLOPT_HEADER, 1);

    ob_start();
    curl_exec($ch);
    $s=ob_get_contents();
    ob_end_clean();

    at the same time this webservice returns also a binary bytecode to generate the image...i tried to continue the code this way but it doesnt return the complete image:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    $image = curl_exec($ch);
    curl_close($ch);

    $n=strpos($s,'ShortCut:')+9;
    $code = substr($s,$n,8);

    header('Content-type: image/png');
    $xim=@imagecreatefromstring($image);

    $xbase = @imagecreatetruecolor(130,168);
    $xback=imagecolorallocate($xbase, 255,255,255); //green
    imagefill($xbase,0,0,$xback);

    $xhead=@imagecreatefrompng('x.png');
    imagecopy($xbase,$xhead,10,0,0,0,108,28);
    imagecopy($xbase,$xim,0, 28, 0, 0, 130,140);
    imagepng($xbase);
     
    warriorvow, Jul 2, 2007 IP
  4. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #4
    hmmmm ...interesting piece of code.. could you show me the output this file for a header ?
     
    killerj, Jul 2, 2007 IP
  5. warriorvow

    warriorvow Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    actually its quite confidential...due to company privacy. anyhow i will describe it to you, its fairly simple. all i wanted to is this:

    1. from that webservice get a certain set of strings from the header
    2. next, generate the image.

    and these 2 steps will be done at the same time.

    to get the header value:
    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt($ch, CURLOPT_HEADER, 1);

    ob_start();
    curl_exec($ch);
    $s=ob_get_contents();

    now from the same url i want also to generate the image on the file. if just to create the image:

    $ch = curl_init();
    $timeout = 0;
    curl_setopt ($ch, CURLOPT_URL, $xmyurl);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    // Getting binary data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

    $image = curl_exec($ch);
    curl_close($ch);

    now...how to combine both functions?
     
    warriorvow, Jul 2, 2007 IP
  6. killerj

    killerj Active Member

    Messages:
    765
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    95
    #6
    i'm not pretty sure with this either .doesn't "imagecreatefromstring" create the needed image ?
     
    killerj, Jul 2, 2007 IP