Beispiel #1
0
 static function pic_convert($side, $data, $design_id, $app_id, $bucket = "open-edit")
 {
     $retun["side"] = $side;
     pt_log("side ---" . $side);
     if ($design_id && $app_id) {
         $tempfilepath = "/tmp/tempFile/" . $app_id . $design_id . '-' . $side;
         if (!is_dir(dirname($tempfilepath . ".svg"))) {
             mkdir(dirname($tempfilepath . ".svg"), 0777, 1);
         }
         file_put_contents($tempfilepath . ".svg", $data);
         $thumbpath = 'designs/' . $app_id . "/" . $design_id . "/" . $side . ".png";
         try {
             ImgConvert::svg2png($tempfilepath . ".svg", $tempfilepath . ".png", "", 200, 200);
             ImgConvert::gen_thumb($tempfilepath . ".png", $tempfilepath . "_thumb.png");
             AliyunOssApi::oss_upload_file($bucket, $tempfilepath . "_thumb.png", $thumbpath);
             $retun["status"] = 'OK';
             $retun["msg"] = "REPLACE_DOMAIN_WITH/" . $thumbpath;
         } catch (Exception $e) {
             $retun["status"] = 'EERROR';
             $retun["msg"] = $e->getMessage();
         }
     } else {
         $retun["status"] = 'EERROR';
         $retun["msg"] = 'design_id or app_id is null';
     }
     return $retun;
 }
Beispiel #2
0
 static function merge_pic($data, $bucket = "open-edit")
 {
     $activityId = $data['activityId'];
     $design = $data['design'];
     $design_id = $design['id'];
     $design_img = $design['image'];
     $des_svgs = db("open")->select_row("select svg_front,svg_back,svg_third,svg_fourth from design_svgs where design_id = ?", $design_id);
     $productStyle = $data['productStyle'];
     foreach ($productStyle as $ps) {
         $styleId = $ps['styleId'];
         $productId = $ps['productId'];
         $ps_image = $ps['image'];
         $color = $ps['color'] ? str_replace("#", "", $ps['color']) : "none";
         $regions = db("open")->select_rows("select r.region,i.side from product_style_images as i\n                                      left join product_style_image_regions as r on r.product_style_image_id = i.id\n                                      where i.product_style_id = ? and i.product_id = ? ", $styleId, $productId);
         $_regions = array();
         foreach ($regions as $r) {
             $_regions[$r['side']] = $r['region'];
         }
         $value = array();
         foreach ($ps_image as $side => $url) {
             if (empty($url)) {
                 continue;
             }
             $design_svg = empty($des_svgs['svg_' . $side]) ? "" : $des_svgs['svg_' . $side];
             if (!empty($_regions[$side])) {
                 $r = $_regions[$side];
                 $t = explode(",", $r);
                 $x = $t['0'] / 2;
                 $y = $t['1'] / 2;
                 $vb = 'viewBox="-' . $x . ' -' . $y . ' 500 500"';
                 $design_svg = "<svg " . $vb . substr($design_svg, 4);
                 $design_svg = self::replace_svg_str($design_svg, 'height="', '"', 500);
                 $design_svg = self::replace_svg_str($design_svg, 'width="', '"', 500);
                 $design_svg = self::replace_svg_str($design_svg, 'height:', "px", 500);
                 //$design_svg = replace_svg_str($design_svg,'width:',"px",500);
             }
             pt_log($design_svg);
             pt_log("-----{$side}");
             //pt_log($design_svg);
             $content = self::gen_svg_content($url, $color, $design_svg);
             //pt_log($content);
             $path = "activitys/{$activityId}/{$productId}_{$styleId}_{$side}";
             $dir = "/tmp/pic/convert";
             $save_path_svg = $dir . "/" . $path . ".svg";
             $save_path_png = $dir . "/" . $path . ".png";
             if (!is_dir(dirname($save_path_svg))) {
                 mkdir(dirname($save_path_svg), 0755, 1);
             }
             pt_log($save_path_svg);
             file_put_contents($save_path_svg, $content);
             ImgConvert::svg2png($save_path_svg, $save_path_png, $color, 500);
             pt_log("-----convert ok!");
             AliyunOssApi::oss_upload_file($bucket, $save_path_png, $path . ".png");
             pt_log("-----upload ok!");
             $value[$side] = "REPLACE_DOMAIN_WITH/" . $path . ".png";
         }
         self::update_activity_product_style($activityId, $productId, $styleId, $value);
     }
 }