<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use Intervention\Image\ImageManagerStatic as Image; use ModStart\Core\Exception\BizException; class ImageUtil { public static function base64Src($gaQ8M, $bOB5d = 'png') { if (!in_array($bOB5d, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($bOB5d) . ';base64,' . base64_encode($gaQ8M); } public static function limitSizeAndDetectOrientation($tGXA6, $bG3rG = 1000, $XmC7Y = 1000) { try { goto vimIK; f60dh: $YKM0f = Image::make($tGXA6); goto cfjXW; GwW7O: $mRq_j = $YKM0f->width(); goto MiaFO; MiaFO: $XOwtM = $YKM0f->height(); goto ipOxF; ipOxF: if ($mRq_j > $bG3rG || $XOwtM > $XmC7Y) { goto EE403; EE403: $MbKut = true; goto AO3Vd; AO3Vd: if ($mRq_j > $bG3rG) { $YKM0f->resize($bG3rG, intval($bG3rG * $XOwtM / $mRq_j)); } goto T478l; T478l: if ($XOwtM > $XmC7Y) { $YKM0f->resize(intval($XmC7Y * $mRq_j / $XOwtM), $XmC7Y); } goto mdWT0; mdWT0: } goto gIFcH; vimIK: $MbKut = false; goto e3pvp; gIFcH: if ($MbKut) { $YKM0f->save($tGXA6); } goto AppaE; jZu85: $bsPK5 = @exif_read_data($tGXA6); goto f60dh; e3pvp: if (ends_with(strtolower($tGXA6), '.webp')) { return; } goto jZu85; cfjXW: if (!empty($bsPK5['Orientation'])) { switch (intval($bsPK5['Orientation'])) { case 2: goto CX2Rv; UF4VQ: break; goto yiHg8; CX2Rv: $YKM0f->flip(); goto OFvb7; OFvb7: $MbKut = true; goto UF4VQ; yiHg8: case 3: goto iQbbO; sQjEF: break; goto C7zlk; sioPb: $MbKut = true; goto sQjEF; iQbbO: $YKM0f->rotate(180); goto sioPb; C7zlk: case 4: goto s5QPV; YMlNR: $MbKut = true; goto rtlpB; s5QPV: $YKM0f->rotate(180); goto VsGi_; VsGi_: $YKM0f->flip(); goto YMlNR; rtlpB: break; goto tTlih; tTlih: case 5: goto VF_Z2; VF_Z2: $YKM0f->rotate(90); goto IW4q8; zObWI: break; goto jsY4Q; IW4q8: $YKM0f->flip(); goto GLX3S; GLX3S: $MbKut = true; goto zObWI; jsY4Q: case 6: goto lwDgI; lwDgI: $YKM0f->rotate(-90); goto p_3hB; p_3hB: $MbKut = true; goto gGTNU; gGTNU: break; goto Yqpow; Yqpow: case 7: goto adGZn; Wb04V: $MbKut = true; goto QRhn0; QRhn0: break; goto byb1p; adGZn: $YKM0f->rotate(90); goto LfJQz; LfJQz: $YKM0f->flip(); goto Wb04V; byb1p: case 8: goto ieTHW; yMxIj: break; goto ZiIfl; n8lbX: $MbKut = true; goto yMxIj; ieTHW: $YKM0f->rotate(90); goto n8lbX; ZiIfl: } } goto GwW7O; AppaE: } catch (\Exception $SXS9c) { throw $SXS9c; } } public static function watermark($YKM0f, $bOB5d, $rFmqf, $WwRq4 = array()) { goto rkEZv; KKeCw: $XOwtM = $haCvx->height(); goto SRMJm; DmDZ4: if ($WwRq4['return']) { return $haCvx->response('png'); } goto j6kTU; F8jy1: BizException::throwsIf('Unknown water position', !in_array($WwRq4['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto ImYk4; oIH05: $haCvx = Image::make($YKM0f); goto oO4L9; oO4L9: $mRq_j = $haCvx->width(); goto KKeCw; DCya9: switch ($bOB5d) { case 'text': goto tUa9I; tUa9I: if (empty($rFmqf)) { return; } goto uZleR; wq4W9: $MbKut = true; goto nBJP9; uZleR: $haCvx->text($rFmqf, $mRq_j - $pIFOE, $XOwtM - $pIFOE, function ($vdauN) use($mRq_j, $XOwtM) { $W7NY7 = max(min($mRq_j, $XOwtM) / 30, 10); $vdauN->file(base_path('vendor/modstart/modstart/resources/font/SourceHanSansCN-Medium.ttf')); $vdauN->size($W7NY7); $vdauN->color('rgba(255, 255, 255, 0.5)'); $vdauN->align('right'); $vdauN->valign('bottom'); }); goto wq4W9; nBJP9: break; goto zPno5; zPno5: case 'image': goto ZSUDs; LS995: $faLne->opacity(50); goto zZrzH; DljMm: break; goto kwbLo; ZSUDs: $XKgoD = FileUtil::savePathToLocalTemp($rFmqf); goto HCV12; zZrzH: $haCvx->insert($faLne, $WwRq4['position'], $pIFOE, $pIFOE); goto NV1IY; HCV12: if (empty($XKgoD) || !file_exists($XKgoD)) { return; } goto xLoOT; Gc_Nx: if ($QhHUK > $Dhbub) { $Dhbub = intval($qodot * $Dhbub / $QhHUK); $QhHUK = $qodot; } else { $QhHUK = intval($qodot * $QhHUK / $Dhbub); $Dhbub = $qodot; } goto uoz0R; xLoOT: $faLne = Image::make($XKgoD); goto Cq0Sg; NV1IY: $MbKut = true; goto DljMm; Cq0Sg: $qodot = max(min($mRq_j, $XOwtM) / 10, 10); goto dASVI; dASVI: $QhHUK = $faLne->width(); goto kb2D4; kb2D4: $Dhbub = $faLne->height(); goto Gc_Nx; uoz0R: $faLne->resize($QhHUK, $Dhbub); goto LS995; kwbLo: } goto DmDZ4; ImYk4: $MbKut = false; goto oIH05; rkEZv: switch ($bOB5d) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto i_aRV; SRMJm: if ($mRq_j < 100 || $XOwtM < 100) { return; } goto Fi1xG; i_aRV: if (!isset($WwRq4['return'])) { $WwRq4['return'] = false; } goto r8oey; Fi1xG: $pIFOE = intval(min($mRq_j, $XOwtM) / 50); goto DCya9; r8oey: if (empty($WwRq4['position'])) { $WwRq4['position'] = 'bottom-right'; } goto F8jy1; j6kTU: if ($MbKut) { $haCvx->save($YKM0f); } goto pQ6i1; pQ6i1: } public static function info($qsQD8) { goto zNrT8; Jh55u: $XOwtM = $haCvx->height(); goto tNHVi; tNHVi: return array('width' => $mRq_j, 'height' => $XOwtM); goto hVOsM; zNrT8: $haCvx = Image::make($qsQD8); goto G4U_l; G4U_l: $mRq_j = $haCvx->width(); goto Jh55u; hVOsM: } }