Ejemplo n.º 1
0
/**
 * 响应并分发请求
 */
$key = isset($_POST["key"]) ? trim($_POST["key"]) : "";
$act = isset($_POST["action"]) ? strtolower(trim($_POST["action"])) : "";
$fileRow = $db->getOne("SELECT file_name FROM uploads WHERE file_key='{$key}' AND user_id=0 LIMIT 1");
$attName = $fileRow["file_name"];
list($result, $code, $error) = $rs->Get($key, $attName);
if ($code != 200) {
    echo json_encode(array("code" => $code, "data" => array("errmsg" => QBox\ErrorMessage($code, $error))));
    exit(-1);
}
$opURL = $result['url'];
switch ($act) {
    case "image_info":
        $url = QBox\FileOp\ImageInfoURL($opURL);
        break;
    case "image_preview":
        $thumbType = isset($_POST["type"]) ? (int) trim($_POST["type"]) : 1;
        $url = QBox\FileOp\ImagePreviewURL($opURL, $thumbType);
        break;
    case "make_style":
        $templPngFile = isset($_POST["imagefile"]) ? trim($_POST["imagefile"]) : "";
        $paramStr = isset($_POST["imagedesc"]) ? trim($_POST["imagedesc"]) : "";
        $quality = isset($_POST["quality"]) ? (int) trim($_POST["quality"]) : 85;
        $url = QBox\FileOp\StylePreviewURL($opURL, $templPngFile, $paramStr, $quality);
        break;
    default:
        $resp = json_encode(array("code" => 400, "data" => array("errmsg" => "Invalid URL, Unknow <action>: {$act}")));
        die($resp);
        exit(-1);
Ejemplo n.º 2
0
if ($code == 200) {
    echo "Mkbucket Success!\n";
} else {
    $msg = QBox\ErrorMessage($code, $error);
    echo "Buckets failed: {$code} - {$msg}\n";
}
list($result, $code, $error) = $rs->Get($key, $key);
echo "===> Get {$key} result:\n";
if ($code == 200) {
    var_dump($result);
} else {
    $msg = QBox\ErrorMessage($code, $error);
    echo "Get failed: {$code} - {$msg}\n";
    exit(-1);
}
$urlImageInfo = QBox\FileOp\ImageInfoURL($result['url']);
echo "===> ImageInfo of {$key}:\n";
echo file_get_contents($urlImageInfo) . "\n";
$targetKey = 'cropped-' . $key;
$source_img_url = $result['url'];
$opts = array("thumbnail" => "!120x120r", "gravity" => "center", "crop" => "!120x120a0a0", "quality" => 85, "rotate" => 45, "format" => "jpg", "auto_orient" => true);
$mogrifyPreviewURL = QBox\FileOp\ImageMogrifyPreviewURL($source_img_url, $opts);
echo "===> ImageMogrifyPreviewURL result:\n";
var_dump($mogrifyPreviewURL);
$imgrs = QBox\RS\NewService($client, "test_thumbnails_bucket");
list($result, $code, $error) = $imgrs->ImageMogrifyAs($targetKey, $source_img_url, $opts);
echo "===> ImageMogrifyAs {$key} result:\n";
if ($code == 200) {
    var_dump($result);
} else {
    $msg = QBox\ErrorMessage($code, $error);