<?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($OAUsL, $gJGJ7 = 'png') { if (!in_array($gJGJ7, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($gJGJ7) . ';base64,' . base64_encode($OAUsL); } public static function limitSizeAndDetectOrientation($aurrr, $aKQ5Q = 1000, $ER1ev = 1000) { goto f2H0t; f2H0t: $ddR8f = array('jpg', 'jpeg', 'png', 'gif'); goto J1ptC; TElzV: if (!in_array($z8pB3, $ddR8f)) { return; } goto Wlo4P; J1ptC: $z8pB3 = FileUtil::extension($aurrr); goto TElzV; Wlo4P: try { goto Zv32Q; kpgYF: $gCaaD = $RKgyl->width(); goto DFg7V; EETfj: if (!empty($Krgj9['Orientation'])) { switch (intval($Krgj9['Orientation'])) { case 2: goto FRxvi; sTDX6: break; goto hRpbc; A42pG: $Aj7Vg = true; goto sTDX6; FRxvi: $RKgyl->flip(); goto A42pG; hRpbc: case 3: goto KVgi_; xWGOK: break; goto qG7xr; KVgi_: $RKgyl->rotate(180); goto PYCJj; PYCJj: $Aj7Vg = true; goto xWGOK; qG7xr: case 4: goto VVUJd; uFNJL: $Aj7Vg = true; goto GXgfM; GXgfM: break; goto ma6f7; oDulZ: $RKgyl->flip(); goto uFNJL; VVUJd: $RKgyl->rotate(180); goto oDulZ; ma6f7: case 5: goto JIX1m; ozrG6: $RKgyl->flip(); goto wS6vh; wS6vh: $Aj7Vg = true; goto xHJv4; xHJv4: break; goto t31Pv; JIX1m: $RKgyl->rotate(90); goto ozrG6; t31Pv: case 6: goto Vw2FO; Vw2FO: $RKgyl->rotate(-90); goto Otp7H; Otp7H: $Aj7Vg = true; goto ireWC; ireWC: break; goto g0Kuw; g0Kuw: case 7: goto ETaKv; Cwv6n: $RKgyl->flip(); goto dJzV1; LAeTt: break; goto CPZ3b; dJzV1: $Aj7Vg = true; goto LAeTt; ETaKv: $RKgyl->rotate(90); goto Cwv6n; CPZ3b: case 8: goto akeEk; V6V03: $Aj7Vg = true; goto aYHav; aYHav: break; goto KYalv; akeEk: $RKgyl->rotate(90); goto V6V03; KYalv: } } goto kpgYF; W_m6V: $RKgyl = Image::make($aurrr); goto EETfj; Zv32Q: $Aj7Vg = false; goto NMz38; DFg7V: $mWXmK = $RKgyl->height(); goto vRrog; NMz38: $Krgj9 = @exif_read_data($aurrr); goto W_m6V; r0QFX: if ($Aj7Vg) { $RKgyl->save($aurrr); } goto CdF36; vRrog: if ($gCaaD > $aKQ5Q || $mWXmK > $ER1ev) { goto C5xDb; C5xDb: $Aj7Vg = true; goto Jzeyg; PAqHA: if ($mWXmK > $ER1ev) { $RKgyl->resize(intval($ER1ev * $gCaaD / $mWXmK), $ER1ev); } goto eiOHO; Jzeyg: if ($gCaaD > $aKQ5Q) { $RKgyl->resize($aKQ5Q, intval($aKQ5Q * $mWXmK / $gCaaD)); } goto PAqHA; eiOHO: } goto r0QFX; CdF36: } catch (\Exception $GrUf4) { throw $GrUf4; } goto ks3un; ks3un: } public static function watermark($RKgyl, $gJGJ7, $ohNZt, $c3D3W = array()) { goto RvDO3; wyRMc: if ($c3D3W['return']) { return $XE1NZ->response('png'); } goto s5DsE; GikT6: if ($gCaaD < 100 || $mWXmK < 100) { return; } goto mxnFC; N6xUt: $Aj7Vg = false; goto xbt7m; fDaCP: BizException::throwsIf('Unknown water position', !in_array($c3D3W['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto N6xUt; P2_1Q: $gCaaD = $XE1NZ->width(); goto T5EUD; mxnFC: $kNHOK = intval(min($gCaaD, $mWXmK) / 50); goto S8Pq0; S8Pq0: switch ($gJGJ7) { case 'text': goto puSqz; WX2aM: $XE1NZ->text($ohNZt, $gCaaD - $kNHOK, $mWXmK - $kNHOK, function ($DIA29) use($gCaaD, $mWXmK) { $M5TSr = max(min($gCaaD, $mWXmK) / 30, 10); $DIA29->file(FontProvider::firstLocalPathOrFail()); $DIA29->size($M5TSr); $DIA29->color('rgba(255, 255, 255, 0.5)'); $DIA29->align('right'); $DIA29->valign('bottom'); }); goto r7BFM; puSqz: if (empty($ohNZt)) { return; } goto WX2aM; uSeIE: break; goto TJlPu; r7BFM: $Aj7Vg = true; goto uSeIE; TJlPu: case 'image': goto i6wzl; im3rO: $VJQUW->opacity(50); goto hPB0A; fXRo4: $VJQUW->resize($QKnPw, $vqeyZ); goto im3rO; ZPN2w: $QKnPw = $VJQUW->width(); goto CNT2m; hPB0A: $XE1NZ->insert($VJQUW, $c3D3W['position'], $kNHOK, $kNHOK); goto FxuhU; CNT2m: $vqeyZ = $VJQUW->height(); goto UIdBI; zaqRO: if (empty($SG9sD) || !file_exists($SG9sD)) { return; } goto W3s91; BqwAZ: break; goto yyHCD; UIdBI: if ($QKnPw > $vqeyZ) { $vqeyZ = intval($P4x0J * $vqeyZ / $QKnPw); $QKnPw = $P4x0J; } else { $QKnPw = intval($P4x0J * $QKnPw / $vqeyZ); $vqeyZ = $P4x0J; } goto fXRo4; W3s91: $VJQUW = Image::make($SG9sD); goto u_AFP; i6wzl: $SG9sD = FileUtil::savePathToLocalTemp($ohNZt); goto zaqRO; FxuhU: $Aj7Vg = true; goto BqwAZ; u_AFP: $P4x0J = max(min($gCaaD, $mWXmK) / 10, 10); goto ZPN2w; yyHCD: } goto wyRMc; T5EUD: $mWXmK = $XE1NZ->height(); goto GikT6; xbt7m: $XE1NZ = Image::make($RKgyl); goto P2_1Q; RvDO3: switch ($gJGJ7) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto kxsjr; s5DsE: if ($Aj7Vg) { $XE1NZ->save($RKgyl); } goto PMbWn; DyT3A: if (empty($c3D3W['position'])) { $c3D3W['position'] = 'bottom-right'; } goto fDaCP; kxsjr: if (!isset($c3D3W['return'])) { $c3D3W['return'] = false; } goto DyT3A; PMbWn: } public static function info($fWBvH) { $XE1NZ = Image::make($fWBvH); return array('width' => $XE1NZ->width(), 'height' => $XE1NZ->height(), 'size' => $XE1NZ->filesize()); } }