<?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($JZuk6, $XcezL = 'png') { if (!in_array($XcezL, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($XcezL) . ';base64,' . base64_encode($JZuk6); } public static function limitSizeAndDetectOrientation($S3tfG, $Yx5zd = 1000, $tY6Wm = 1000) { goto byNzR; PO9kw: try { goto ypGKy; AFNOw: if ($EBuGi) { $suPvt->save($S3tfG); } goto W6sFr; C_epC: $r3IZu = $suPvt->width(); goto ASQdm; ASQdm: $I0ifH = $suPvt->height(); goto UE8Fc; ypGKy: $EBuGi = false; goto mDxuG; obrc2: $suPvt = Image::make($S3tfG); goto b4py3; b4py3: if (!empty($c3180['Orientation'])) { switch (intval($c3180['Orientation'])) { case 2: goto iITdK; JbELi: break; goto S5Xjh; iITdK: $suPvt->flip(); goto Ck9t9; Ck9t9: $EBuGi = true; goto JbELi; S5Xjh: case 3: goto tJp8I; tJp8I: $suPvt->rotate(180); goto dVn5d; deDJU: break; goto H7Gnr; dVn5d: $EBuGi = true; goto deDJU; H7Gnr: case 4: goto E8esU; N9XNW: break; goto FZU8i; yXTbr: $suPvt->flip(); goto DxQfs; DxQfs: $EBuGi = true; goto N9XNW; E8esU: $suPvt->rotate(180); goto yXTbr; FZU8i: case 5: goto s3ZLR; V3TUA: $EBuGi = true; goto PAZyt; s3ZLR: $suPvt->rotate(90); goto eeCdo; eeCdo: $suPvt->flip(); goto V3TUA; PAZyt: break; goto JowK6; JowK6: case 6: goto Z78wQ; VfFQq: break; goto DbtQy; YlIjq: $EBuGi = true; goto VfFQq; Z78wQ: $suPvt->rotate(-90); goto YlIjq; DbtQy: case 7: goto AJjAo; AJjAo: $suPvt->rotate(90); goto BtBYo; us9ao: $EBuGi = true; goto PvkRV; BtBYo: $suPvt->flip(); goto us9ao; PvkRV: break; goto HoBr2; HoBr2: case 8: goto bYFg3; kl3zj: $EBuGi = true; goto FBPmg; FBPmg: break; goto AXn3M; bYFg3: $suPvt->rotate(90); goto kl3zj; AXn3M: } } goto C_epC; mDxuG: $c3180 = @exif_read_data($S3tfG); goto obrc2; UE8Fc: if ($r3IZu > $Yx5zd || $I0ifH > $tY6Wm) { goto Zihxh; KSM5j: if ($I0ifH > $tY6Wm) { $suPvt->resize(intval($tY6Wm * $r3IZu / $I0ifH), $tY6Wm); } goto AHZhV; h1OmJ: if ($r3IZu > $Yx5zd) { $suPvt->resize($Yx5zd, intval($Yx5zd * $I0ifH / $r3IZu)); } goto KSM5j; Zihxh: $EBuGi = true; goto h1OmJ; AHZhV: } goto AFNOw; W6sFr: } catch (\Exception $Y5fnH) { throw $Y5fnH; } goto O0OWC; byNzR: $OyfKl = array('jpg', 'jpeg', 'png', 'gif'); goto OibC1; zEixc: if (!in_array($Zb77B, $OyfKl)) { return; } goto PO9kw; OibC1: $Zb77B = FileUtil::extension($S3tfG); goto zEixc; O0OWC: } public static function watermark($suPvt, $XcezL, $DTnPC, $oOr7L = array()) { goto cO2_y; q7KqW: $dYVhD = intval(min($r3IZu, $I0ifH) / 50); goto IWhit; PjWdA: if ($oOr7L['return']) { return $ZWSkD->response('png'); } goto CPZKa; uh6Ah: $r3IZu = $ZWSkD->width(); goto TcgVA; xB4oC: BizException::throwsIf('Unknown water position', !in_array($oOr7L['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto h2S1P; WSSXz: if (!isset($oOr7L['return'])) { $oOr7L['return'] = false; } goto GQlJE; odFOT: if ($r3IZu < 100 || $I0ifH < 100) { return; } goto q7KqW; TcgVA: $I0ifH = $ZWSkD->height(); goto odFOT; GQlJE: if (empty($oOr7L['position'])) { $oOr7L['position'] = 'bottom-right'; } goto xB4oC; cO2_y: switch ($XcezL) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto WSSXz; OxawK: $ZWSkD = Image::make($suPvt); goto uh6Ah; h2S1P: $EBuGi = false; goto OxawK; IWhit: switch ($XcezL) { case 'text': goto vwfdi; n2ko2: $ZWSkD->text($DTnPC, $r3IZu - $dYVhD, $I0ifH - $dYVhD, function ($boxQL) use($r3IZu, $I0ifH) { $n2Tmx = max(min($r3IZu, $I0ifH) / 30, 10); $boxQL->file(FontProvider::firstLocalPathOrFail()); $boxQL->size($n2Tmx); $boxQL->color('rgba(255, 255, 255, 0.5)'); $boxQL->align('right'); $boxQL->valign('bottom'); }); goto faM8c; faM8c: $EBuGi = true; goto y0s6Z; vwfdi: if (empty($DTnPC)) { return; } goto n2ko2; y0s6Z: break; goto mrbhe; mrbhe: case 'image': goto JcVJK; IxTA5: if (empty($qv9k6) || !file_exists($qv9k6)) { return; } goto d38If; d38If: $W98qF = Image::make($qv9k6); goto vug8Q; BfPPP: $W98qF->opacity(50); goto YYtCt; msrfp: $zYMJJ = $W98qF->height(); goto yds3j; GIDaY: break; goto Ly0Pp; vug8Q: $Cq2Q4 = max(min($r3IZu, $I0ifH) / 10, 10); goto PEr6K; yds3j: if ($OP1c1 > $zYMJJ) { $zYMJJ = intval($Cq2Q4 * $zYMJJ / $OP1c1); $OP1c1 = $Cq2Q4; } else { $OP1c1 = intval($Cq2Q4 * $OP1c1 / $zYMJJ); $zYMJJ = $Cq2Q4; } goto VqxnW; YYtCt: $ZWSkD->insert($W98qF, $oOr7L['position'], $dYVhD, $dYVhD); goto xpBTy; JcVJK: $qv9k6 = FileUtil::savePathToLocalTemp($DTnPC); goto IxTA5; PEr6K: $OP1c1 = $W98qF->width(); goto msrfp; xpBTy: $EBuGi = true; goto GIDaY; VqxnW: $W98qF->resize($OP1c1, $zYMJJ); goto BfPPP; Ly0Pp: } goto PjWdA; CPZKa: if ($EBuGi) { $ZWSkD->save($suPvt); } goto staE5; staE5: } public static function info($RLMU5) { $ZWSkD = Image::make($RLMU5); return array('width' => $ZWSkD->width(), 'height' => $ZWSkD->height(), 'size' => $ZWSkD->filesize()); } }