<?php require_once "Kraken.php"; $kraken = new Kraken("your-api-key", "your-api-secret"); $params = array("file" => "/path/to/image/file.jpg", "wait" => true, "s3_store" => array("key" => "your-amazon-access-key", "secret" => "your-amazon-secret-key", "bucket" => "destination-bucket")); $data = $kraken->upload($params); if ($data["success"]) { echo "Success. Optimized image URL: " . $data["kraked_url"]; } else { echo "Fail. Error message: " . $data["error"]; }
<?php require_once "Kraken.php"; $kraken = new Kraken("your-api-key", "your-api-secret"); $params = array("url" => "http://url-to-image/file.jpg", "wait" => true); $data = $kraken->url($params); if (!empty($data["success"])) { // optimization succeeded echo "Success. Optimized image URL: " . $data["kraked_url"]; } elseif (isset($data["message"])) { // something went wrong with the optimization echo "Optimization failed. Error message from Kraken.io: " . $data["message"]; } else { // something went wrong with the request echo "cURL request failed. Error message: " . $data["error"]; }
/** * check api status * @return boolean */ public function getAPIStatus() { if ($this->apiKey && $this->apiSecret) { $kraken = new Kraken($this->apiKey, $this->apiSecret); $status = $kraken->status(); return $status; } return false; }
function optimize_image($image_path, $type, $resize = false) { $settings = $this->kraken_settings; $kraken = new Kraken($settings['api_key'], $settings['api_secret']); if (!empty($type)) { $lossy = $type === 'lossy'; } else { $lossy = $settings['api_lossy'] === 'lossy'; } $params = array('file' => $image_path, 'wait' => true, 'lossy' => $lossy, 'origin' => 'wp'); $preserve_meta_arr = array(); if ($settings['preserve_meta_date']) { $preserve_meta_arr[] = 'date'; } if ($settings['preserve_meta_copyright']) { $preserve_meta_arr[] = 'copyright'; } if ($settings['preserve_meta_geotag']) { $preserve_meta_arr[] = 'geotag'; } if ($settings['preserve_meta_orientation']) { $preserve_meta_arr[] = 'orientation'; } if ($settings['preserve_meta_profile']) { $preserve_meta_arr[] = 'profile'; } if ($settings['chroma']) { $params['sampling_scheme'] = $settings['chroma']; } if (count($preserve_meta_arr)) { $params['preserve_meta'] = $preserve_meta_arr; } if ($settings['auto_orient']) { $params['auto_orient'] = true; } if ($resize) { $width = (int) $settings['resize_width']; $height = (int) $settings['resize_height']; if ($width && $height) { $params['resize'] = array('strategy' => 'auto', 'width' => $width, 'height' => $height); } elseif ($width && !$height) { $params['resize'] = array('strategy' => 'landscape', 'width' => $width); } elseif ($height && !$width) { $params['resize'] = array('strategy' => 'portrait', 'height' => $height); } } if (isset($settings['jpeg_quality']) && $settings['jpeg_quality'] > 0) { $params['quality'] = (int) $settings['jpeg_quality']; } set_time_limit(400); $data = $kraken->upload($params); $data['type'] = !empty($type) ? $type : $settings['api_lossy']; return $data; }
function optimize_image($image_path, $type) { $settings = $this->kraken_settings; $kraken = new Kraken($settings['api_key'], $settings['api_secret']); if (!empty($type)) { $lossy = $type === 'lossy'; } else { $lossy = $settings['api_lossy'] === "lossy"; } $params = array("file" => $image_path, "wait" => true, "lossy" => $lossy, "origin" => "wp"); try { $data = $kraken->upload($params); } catch (Exception $e) { } $data['type'] = !empty($type) ? $type : $settings['api_lossy']; return $data; }