key = $key; } /** * onejob * A really basic starter function to run basic jobs through blitline. * See the examples on http://www.blitline.com/docs/examples for what the call the function names, and the paramaters. * * @param $src * @param $function * @param $params * @return bool */ public function onejob($src, $function, $params) { $extension = '.'.array_pop(explode('.',$src)); $id = 'image_'.time(); $packet = array(); $packet['application_id'] = $this->key; $packet['src'] = $src; $packet['functions'] = array( array('name'=>$function, 'params'=>$params, 'save'=>array('image_identifier'=>$id, 'extension' => $extension ) ) ); if ($extension == ".png") { $packet['functions'][0]['save']['png_quantize'] = true; } //print_r($packet); if ($this->sendRequest(array('json'=>json_encode($packet)))) { $result = json_decode($this->response, true); if (count(@$result['results']['images'])) { return array_pop($result['results']['images'])['s3_url']; } else { //print_r($result); return false; } } else { echo "Something went wrong with the send."; } } /** * Send Request * Generic function to send whatever request has been prepared, and save the response. * @return bool */ private function sendRequest($data) { $url = $this->url; //init the curl request $ch = curl_init(); $qry_str = http_build_query($data); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $qry_str); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, '30'); //send it off & save the result $content = trim(curl_exec($ch)); curl_close($ch); if ($content) { $this->response = $content; return true; } else { return false; } } }