Exemplo n.º 1
0
/**
 * 生成 JSON 格式的输出
 */
function generate_output_data($result, $code, $error)
{
    $result = $code == 200 ? $result : array("errmsg" => QBox_ErrorMessage($code, $error));
    return json_encode(array("code" => $code, "data" => $result));
}
Exemplo n.º 2
0
$tblName = 'tblName';
$rs = QBox_RS_NewService($client, $tblName);
$key = '2.jpg';
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);
    echo "ImageMogrifyAs failed: {$code} - {$msg}\n";
    exit(-1);
}
Exemplo n.º 3
0
 * @license MIT License {@link http://www.opensource.org/licenses/mit-license.php}
 */
header('Pragma: no-cache');
header('Cache-Control: no-store');
header('Content-type: application/json');
require_once 'bootstrap.php';
/**
 * 响应并分发请求
 */
$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;