<?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($Bj5wF, $aHcWY = 'png') { if (!in_array($aHcWY, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($aHcWY) . ';base64,' . base64_encode($Bj5wF); } public static function limitSizeAndDetectOrientation($VF_G6, $hsc2E = 1000, $rUHNt = 1000) { goto MiTt1; MiTt1: $z64vc = array('jpg', 'jpeg', 'png', 'gif'); goto kgcLs; alFPG: if (!in_array($PqKSi, $z64vc)) { return; } goto higj4; higj4: try { goto iVHA_; iVHA_: $S8KVq = false; goto Ol0qU; pwGMJ: if ($NxzmO > $hsc2E || $JUimT > $rUHNt) { goto xIjzD; xIjzD: $S8KVq = true; goto lXRyK; lXRyK: if ($NxzmO > $hsc2E) { $l5uyd->resize($hsc2E, intval($hsc2E * $JUimT / $NxzmO)); } goto xoLIT; xoLIT: if ($JUimT > $rUHNt) { $l5uyd->resize(intval($rUHNt * $NxzmO / $JUimT), $rUHNt); } goto vzgGA; vzgGA: } goto TOksI; Dzd_0: if (!empty($SfuSI['Orientation'])) { switch (intval($SfuSI['Orientation'])) { case 2: goto pYTOe; zXSoP: $S8KVq = true; goto gelr0; gelr0: break; goto DsMkA; pYTOe: $l5uyd->flip(); goto zXSoP; DsMkA: case 3: goto J8k2m; TDe8a: $S8KVq = true; goto T9buE; J8k2m: $l5uyd->rotate(180); goto TDe8a; T9buE: break; goto NY7wI; NY7wI: case 4: goto XCdX7; XCdX7: $l5uyd->rotate(180); goto OBTpr; b3aK2: break; goto pqRdG; skWJ2: $S8KVq = true; goto b3aK2; OBTpr: $l5uyd->flip(); goto skWJ2; pqRdG: case 5: goto L8_6n; L8_6n: $l5uyd->rotate(90); goto bkkpD; bkkpD: $l5uyd->flip(); goto kUS4o; rXprS: break; goto UPKWJ; kUS4o: $S8KVq = true; goto rXprS; UPKWJ: case 6: goto sMxzS; ApIcO: break; goto wn9Jq; fi2VM: $S8KVq = true; goto ApIcO; sMxzS: $l5uyd->rotate(-90); goto fi2VM; wn9Jq: case 7: goto kJWX3; kJWX3: $l5uyd->rotate(90); goto FekV0; FekV0: $l5uyd->flip(); goto slymk; d3U6d: break; goto hv2bn; slymk: $S8KVq = true; goto d3U6d; hv2bn: case 8: goto SyVAp; hkI66: $S8KVq = true; goto NaoPp; SyVAp: $l5uyd->rotate(90); goto hkI66; NaoPp: break; goto ZEGOH; ZEGOH: } } goto WzHeH; Ol0qU: $SfuSI = @exif_read_data($VF_G6); goto l94wH; WzHeH: $NxzmO = $l5uyd->width(); goto I0SSU; I0SSU: $JUimT = $l5uyd->height(); goto pwGMJ; l94wH: $l5uyd = Image::make($VF_G6); goto Dzd_0; TOksI: if ($S8KVq) { $l5uyd->save($VF_G6); } goto VUiuE; VUiuE: } catch (\Exception $WVwSN) { throw $WVwSN; } goto vWVgA; kgcLs: $PqKSi = FileUtil::extension($VF_G6); goto alFPG; vWVgA: } public static function watermark($l5uyd, $aHcWY, $Afv_G, $LEG8W = array()) { goto gznPT; P8TM8: $mtZOq = Image::make($l5uyd); goto AVaQ5; o6n64: switch ($aHcWY) { case 'text': goto SOxsR; mfHdu: $S8KVq = true; goto lmESs; SOxsR: if (empty($Afv_G)) { return; } goto uBuXR; uBuXR: $mtZOq->text($Afv_G, $NxzmO - $tBytK, $JUimT - $tBytK, function ($sIeZA) use($NxzmO, $JUimT) { $v1z0o = max(min($NxzmO, $JUimT) / 30, 10); $sIeZA->file(FontProvider::firstLocalPathOrFail()); $sIeZA->size($v1z0o); $sIeZA->color('rgba(255, 255, 255, 0.5)'); $sIeZA->align('right'); $sIeZA->valign('bottom'); }); goto mfHdu; lmESs: break; goto MqFoz; MqFoz: case 'image': goto p1jgh; GyVEI: if (empty($hG3w2) || !file_exists($hG3w2)) { return; } goto DnhDG; ieipB: $CcreL = max(min($NxzmO, $JUimT) / 10, 10); goto YjhcV; F5V29: $mtZOq->insert($Rj1PV, $LEG8W['position'], $tBytK, $tBytK); goto ibKht; DnhDG: $Rj1PV = Image::make($hG3w2); goto ieipB; bOUlj: $Rj1PV->resize($GYKkl, $vOO1P); goto OuDkU; cvSru: break; goto iCY8j; IjOmC: $vOO1P = $Rj1PV->height(); goto yua_n; yua_n: if ($GYKkl > $vOO1P) { $vOO1P = intval($CcreL * $vOO1P / $GYKkl); $GYKkl = $CcreL; } else { $GYKkl = intval($CcreL * $GYKkl / $vOO1P); $vOO1P = $CcreL; } goto bOUlj; OuDkU: $Rj1PV->opacity(50); goto F5V29; ibKht: $S8KVq = true; goto cvSru; p1jgh: $hG3w2 = FileUtil::savePathToLocalTemp($Afv_G); goto GyVEI; YjhcV: $GYKkl = $Rj1PV->width(); goto IjOmC; iCY8j: } goto pfrR2; AvJV3: if (!isset($LEG8W['return'])) { $LEG8W['return'] = false; } goto F2Z8L; G25qZ: if ($S8KVq) { $mtZOq->save($l5uyd); } goto Z65xs; gznPT: switch ($aHcWY) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto AvJV3; pfrR2: if ($LEG8W['return']) { return $mtZOq->response('png'); } goto G25qZ; KWOrU: $JUimT = $mtZOq->height(); goto AjmHR; Azddy: BizException::throwsIf('Unknown water position', !in_array($LEG8W['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto L5NOl; AVaQ5: $NxzmO = $mtZOq->width(); goto KWOrU; L5NOl: $S8KVq = false; goto P8TM8; AjmHR: if ($NxzmO < 100 || $JUimT < 100) { return; } goto YkZC4; F2Z8L: if (empty($LEG8W['position'])) { $LEG8W['position'] = 'bottom-right'; } goto Azddy; YkZC4: $tBytK = intval(min($NxzmO, $JUimT) / 50); goto o6n64; Z65xs: } public static function info($aYJAK) { $mtZOq = Image::make($aYJAK); return array('width' => $mtZOq->width(), 'height' => $mtZOq->height(), 'size' => $mtZOq->filesize()); } }