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?
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);
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?