<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use Intervention\Image\ImageManagerStatic as Image; use ModStart\Core\Exception\BizException; use ModStart\Core\Provider\FontProvider; class ImageUtil { public static function base64Src($Bx8hl, $FDNZs = 'png') { if (!in_array($FDNZs, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($FDNZs) . ';base64,' . base64_encode($Bx8hl); } public static function limitSizeAndDetectOrientation($LclBr, $GJiLe = 1000, $kKIrG = 1000) { goto y6jkU; y6jkU: $snpR_ = array('jpg', 'jpeg', 'png', 'gif'); goto ic3DR; IlRs2: try { goto TgnqP; iIkno: $aI0SX = $D_3cs->width(); goto K4SVg; FH1Y6: if ($aI0SX > $GJiLe || $JE2FY > $kKIrG) { goto os_Sj; vjNHN: if ($aI0SX > $GJiLe) { $D_3cs->resize($GJiLe, intval($GJiLe * $JE2FY / $aI0SX)); } goto UeRuh; os_Sj: $has4t = true; goto vjNHN; UeRuh: if ($JE2FY > $kKIrG) { $D_3cs->resize(intval($kKIrG * $aI0SX / $JE2FY), $kKIrG); } goto zSaE2; zSaE2: } goto jWQtO; K4SVg: $JE2FY = $D_3cs->height(); goto FH1Y6; VWoz4: if (!empty($IQyZm['Orientation'])) { switch (intval($IQyZm['Orientation'])) { case 2: goto y_b4g; m7gJE: break; goto e6khw; hKMVb: $has4t = true; goto m7gJE; y_b4g: $D_3cs->flip(); goto hKMVb; e6khw: case 3: goto BBits; bIkjr: break; goto LmO8d; isWSR: $has4t = true; goto bIkjr; BBits: $D_3cs->rotate(180); goto isWSR; LmO8d: case 4: goto Yxt59; Yxt59: $D_3cs->rotate(180); goto Fwfsl; kQeZX: break; goto WlE3R; Fwfsl: $D_3cs->flip(); goto mBXvc; mBXvc: $has4t = true; goto kQeZX; WlE3R: case 5: goto je6zW; je6zW: $D_3cs->rotate(90); goto pidO4; pidO4: $D_3cs->flip(); goto oMmXW; oMmXW: $has4t = true; goto UD3bq; UD3bq: break; goto ZFduM; ZFduM: case 6: goto iBWps; cReZc: break; goto gV63u; iBWps: $D_3cs->rotate(-90); goto lK9cs; lK9cs: $has4t = true; goto cReZc; gV63u: case 7: goto A1UcX; A1UcX: $D_3cs->rotate(90); goto o2H7l; DdVWg: $has4t = true; goto t1XfJ; o2H7l: $D_3cs->flip(); goto DdVWg; t1XfJ: break; goto OxP1l; OxP1l: case 8: goto luF0K; RZGvN: $has4t = true; goto xIuaL; xIuaL: break; goto APCa8; luF0K: $D_3cs->rotate(90); goto RZGvN; APCa8: } } goto iIkno; izQ7B: $D_3cs = Image::make($LclBr); goto VWoz4; jWQtO: if ($has4t) { $D_3cs->save($LclBr); } goto Lmyl_; wC192: $IQyZm = @exif_read_data($LclBr); goto izQ7B; TgnqP: $has4t = false; goto wC192; Lmyl_: } catch (\Exception $xpJqz) { throw $xpJqz; } goto rnQ_o; JeH6U: if (!in_array($nsKya, $snpR_)) { return; } goto IlRs2; ic3DR: $nsKya = FileUtil::extension($LclBr); goto JeH6U; rnQ_o: } public static function watermark($D_3cs, $FDNZs, $cgjRu, $yFteQ = array()) { goto dDwJM; anUcE: $has4t = false; goto ETYNJ; nvAjb: if (empty($yFteQ['position'])) { $yFteQ['position'] = 'bottom-right'; } goto xvsaN; ZJzrv: $aI0SX = $xlknE->width(); goto b7SsG; ETYNJ: $xlknE = Image::make($D_3cs); goto ZJzrv; Agjko: if ($has4t) { $xlknE->save($D_3cs); } goto pki0e; PZJL2: if ($aI0SX < 100 || $JE2FY < 100) { return; } goto ceN9v; fFvh2: if ($yFteQ['return']) { return $xlknE->response('png'); } goto Agjko; dDwJM: switch ($FDNZs) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto kOhKR; xvsaN: BizException::throwsIf('Unknown water position', !in_array($yFteQ['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto anUcE; b7SsG: $JE2FY = $xlknE->height(); goto PZJL2; kOhKR: if (!isset($yFteQ['return'])) { $yFteQ['return'] = false; } goto nvAjb; ZdEWA: switch ($FDNZs) { case 'text': goto EQHW_; jrFna: $xlknE->text($cgjRu, $aI0SX - $eL9Ko, $JE2FY - $eL9Ko, function ($zBBHf) use($aI0SX, $JE2FY) { $UG0yd = max(min($aI0SX, $JE2FY) / 30, 10); $zBBHf->file(FontProvider::firstLocalPathOrFail()); $zBBHf->size($UG0yd); $zBBHf->color('rgba(255, 255, 255, 0.5)'); $zBBHf->align('right'); $zBBHf->valign('bottom'); }); goto ctmu5; ctmu5: $has4t = true; goto NyeC7; EQHW_: if (empty($cgjRu)) { return; } goto jrFna; NyeC7: break; goto relFK; relFK: case 'image': goto LQMkz; nEpna: $Plw3b->opacity(50); goto kHLzP; ijosP: $ORgwx = max(min($aI0SX, $JE2FY) / 10, 10); goto pWbkt; Ib9KD: $Vsw77 = $Plw3b->height(); goto VbgQ7; ZpxH6: $has4t = true; goto OgExq; hoGIc: $Plw3b = Image::make($wJH3t); goto ijosP; cqsvp: $Plw3b->resize($j8tfp, $Vsw77); goto nEpna; VbgQ7: if ($j8tfp > $Vsw77) { $Vsw77 = intval($ORgwx * $Vsw77 / $j8tfp); $j8tfp = $ORgwx; } else { $j8tfp = intval($ORgwx * $j8tfp / $Vsw77); $Vsw77 = $ORgwx; } goto cqsvp; LQMkz: $wJH3t = FileUtil::savePathToLocalTemp($cgjRu); goto CNcRB; pWbkt: $j8tfp = $Plw3b->width(); goto Ib9KD; CNcRB: if (empty($wJH3t) || !file_exists($wJH3t)) { return; } goto hoGIc; OgExq: break; goto VOceo; kHLzP: $xlknE->insert($Plw3b, $yFteQ['position'], $eL9Ko, $eL9Ko); goto ZpxH6; VOceo: } goto fFvh2; ceN9v: $eL9Ko = intval(min($aI0SX, $JE2FY) / 50); goto ZdEWA; pki0e: } public static function info($yHf3t) { $xlknE = Image::make($yHf3t); return array('width' => $xlknE->width(), 'height' => $xlknE->height(), 'size' => $xlknE->filesize()); } }